Skip to content
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]: Must use import to load ES Module: /project/newrelic.js #810

Closed
btakita opened this issue Jul 20, 2021 · 1 comment

Comments

@btakita
Copy link

btakita commented Jul 20, 2021

The Error [ERR_REQUIRE_ESM]: Must use import to load ES Module: /project/newrelic.js occurs when loading newrelic from a package using ES Module.

Expected Behavior

newrelic package.json file should include either "module": "./index.mjs" or:

"exports": {
	".": {
		"require": "./index.js,
		"import": "./index.mjs"
	}
}

Steps to Reproduce

Create a npm package with "type": "module" in package.json.

Add & configure newrelic.

Run server.

@michaelgoin
Copy link
Member

Hi @btakita ,

We do not currently support ES modules. If we do add support in the future, we will likely support both setups.

I would recommend adding a thumbs-up to this issue: #553.

That being said, your error is something I haven't seen when using the agent with ES modules. Typically, if you import the agent it loads fine. There has been some issue with the config file, which an external contribution has allowed us to load 'newrelic.cjs' files now.

As such, you might try renaming your newrelic.js config file to newrelic.cjs and then use import to import our newrelic package as a CommonJS module.

At that point... I don't expect any instrumentation to work but you likely can use the API.

Closing this as we will track things through the feature-request I shared above but happy to continue chatting about getting the import to work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants