-
Notifications
You must be signed in to change notification settings - Fork 409
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Error [ERR_REQUIRE_ESM]: require() of ES Module #2275
Comments
Please review the error message. It is stating that you are are using the |
Hi @jsumners-nr ,
Error:
I tried multiple workaround but nothing worked. I would highly appreciate your help in this. |
👋 thank you for the report. Please provide a minimal reproducible example. Doing so will help us diagnose the issue. It should be the bare minimum code needed to trigger the issue, and easily runnable without any changes or extra code. You may use a GitHub repository to host the code if it is too much to fit into a code block (or two). |
DescriptionFacing error while trying to integrate newRelic in nodejs. Using ES syntax. Expected BehaviorShoule be up and running as it is running in other repos where I am using commonJS Steps to Reproduce1.) Added
3.) a.) Attempting to load New Relic in the app start file before loading environment variables from the config is problematic because step 2 involves importing envConfig.
b.)Attempted to load the newrelic.cjs file created in the following manner:
4.) Upon executing the command npm start, the following error is encountered:
Your EnvironmentEnv: Node version: v20.13.1 Additional contextWorkaround that i tried: @jsumners-nr Let me know if you need anything else from my side. |
The linked documentation, specifically the section regarding the configuration file https://docs.newrelic.com/docs/apm/agents/nodejs-agent/installation-configuration/es-modules/#configuration, clearly highlights that we only support CommonJS modules for configuration files. Due to the way ES modules are loaded by Node.js at this time, it is not possible to mix a CommonJS configuration with other files written as ESM. The only possible way to do so would be to do something like: // newrelic.cjs
main().then(() => {}).catch(console.error)
async function main() {
const config = await import('./config.js')
module.exports.config = {
app_name: [config.app_name],
license_key: 'invalid'
}
} But that will not work because, as stated in the linked documentation, we use node-newrelic/lib/config/index.js Lines 1700 to 1702 in 07a841b
You can still read environment variables in your 'use strict'
require('dotenv').config()
module.exports.config = {
app_name: [process.env.MY_COOL_APP_NAME],
license: process.env.MY_LICENSE_KEY
} |
@jainritik you also don't need to load alternative configurations and assign in a file. All of our configurations support environment variable equivalents and it is documented here. so if you just specify |
@bizob2828 @jsumners-nr So actually from config I am trying to get File structure newrelic.ejs and config are in root dir.
this is what I am trying to do. Still getting some errors
|
I recommend reviewing https://blog.platformatic.dev/handling-environment-variables-in-nodejs and paying particular attention to the discussion around Other than that, this seems to be out of scope, and is not a bug. Everything is working as intended, and the issue is application structure. |
Description
Still facing same issue( #553 ):
New Relic for Node.js is disabled due to an error:
newrelic.cjs file:
once client is created I have imported newrelic in the start of app as following:
import 'newrelic';
Can you please help me in this @bizob2828 I tried multiple workarounds as well like trying to use .js file
@coreyarnold @solocommand @jedashford @drmrbrewer @bizob2828
The text was updated successfully, but these errors were encountered: