newrelic / node-newrelic

New Relic Node.js agent code base. Developers are welcome to create pull requests here, please see our contributing guidelines. For New Relic technical support, please go to http://support.newrelic.com.
Apache License 2.0
971 stars 399 forks source link

Remix Vite ESM loader fails to start #2482

Closed kenn closed 3 months ago

kenn commented 3 months ago

Description

I have installed NewRelic with Remix Vite and ESM, but it fails to start the server in production build.

> node --experimental-loader newrelic/esm-loader.mjs -r newrelic ./server.js
==> Exited with status 1
==> Common ways to troubleshoot your deploy: https://docs.render.com/troubleshooting-deploys
(node:102) ExperimentalWarning: `--experimental-loader` may be removed in the future; instead use `register()`:
--import 'data:text/javascript,import { register } from "node:module"; import { pathToFileURL } from "node:url"; register("newrelic/esm-loader.mjs", pathToFileURL("./"));'
debug
(Use `node --trace-warnings ...` to show where the warning was created)
file:///opt/render/project/src/frontend/build/server/index.js:36
import { relations, desc, isNull, isNotNull, gte, lte, eq, and, count, inArray, asc, sql } from "drizzle-orm";
                                                           ^^^
SyntaxError: The requested module 'drizzle-orm' does not provide an export named 'and'
    at ModuleJob._instantiate (node:internal/modules/esm/module_job:134:21)
    at async ModuleJob.run (node:internal/modules/esm/module_job:217:5)
    at async ModuleLoader.import (node:internal/modules/esm/loader:316:24)
    at async file:///opt/render/project/src/frontend/server.js:21:7
Node.js v20.16.0
 ELIFECYCLE  Command failed with exit code 1.

I don't have issues with starting the server without --experimental-loader for NewRelic.

> node ./server.js
🔌 setting up drizzle client
✅ app ready at http://localhost:10000
HEAD / 200 - - 153.861 ms
==> Your service is live 🎉

Expected Behavior

Start without issue

Troubleshooting or NR Diag results

N/A

Steps to Reproduce

Compare these two start modes:

Success:

node ./server.js

Failure:

node --experimental-loader newrelic/esm-loader.mjs -r newrelic ./server.js

Your Environment

Additional context

We were using NewRelic before upgrading Remix to Vite / ESM.

When we completed upgrade, we gave up on NewRelic. This is our second trial thinking updated node-newrelic v12 might fix the issue, but still fails.

workato-integration[bot] commented 3 months ago

https://new-relic.atlassian.net/browse/NR-303619

bizob2828 commented 3 months ago

@kenn the ESM loader is experimental and it's just proxy to import-in-the-middle. This would be a bug with that package but if you look at issues it's like this one. If you want to use the New Relic Node.js agent I recommend you use common js format and not ESM until they can resolve this issue. I'm going to close this issue