nodejs / import-in-the-middle

Like `require-in-the-middle`, but for ESM import
https://www.npmjs.com/package/import-in-the-middle
Apache License 2.0
72 stars 27 forks source link

import-in-the-middle' failed to wrap 'file:///app/node_modules/@prisma/client/default.js' #116

Closed IamR3m closed 5 months ago

IamR3m commented 5 months ago

Expected Behavior

An app should run successfully

Actual Behavior

Googling points me to this repository. An app fails with

Error: 'import-in-the-middle' failed to wrap 'file:///app/node_modules/@prisma/client/default.js'
    at getSource (/app/node_modules/import-in-the-middle/hook.js:304:21)
    at async load (/app/node_modules/import-in-the-middle/hook.js:319:26)
    at async nextLoad (node:internal/modules/esm/hooks:864:22)
    at async Hooks.load (node:internal/modules/esm/hooks:447:20)
    at async handleMessage (node:internal/modules/esm/worker:196:18) {
  cause: Error: Unexpected import statement in CJS module.
    at @:1:8
      at esmSyntaxErr (/app/node_modules/cjs-module-lexer/lexer.js:1153:24)
      at throwIfImportStatement (/app/node_modules/cjs-module-lexer/lexer.js:1183:13)
      at parseSource (/app/node_modules/cjs-module-lexer/lexer.js:113:13)
      at parseCJS (/app/node_modules/cjs-module-lexer/lexer.js:43:5)
      at getCjsExports (/app/node_modules/import-in-the-middle/lib/get-exports.js:37:20)
      at getExports (/app/node_modules/import-in-the-middle/lib/get-exports.js:100:12)
      at async /app/node_modules/import-in-the-middle/lib/get-exports.js:48:28
      at async Promise.all (index 0)
      at async getCjsExports (/app/node_modules/import-in-the-middle/lib/get-exports.js:40:5)
      at async /app/node_modules/import-in-the-middle/lib/get-exports.js:48:28 {
    code: 'ERR_LEXER_ESM_SYNTAX',
    loc: 7
  }
}

after updating dependencies and implementing some feature on my code not affecting sentry or prisma.

Steps to Reproduce the Problem

  1. Create ESM project
  2. Install prisma
  3. Install @sentry/node
  4. build and deploy project on Google Cloud Run

Specifications

timfish commented 5 months ago

There's already an open Sentry issue for this: https://github.com/getsentry/sentry-javascript/issues/12325

And a PR in this repository to fix it: https://github.com/DataDog/import-in-the-middle/pull/108

timfish commented 5 months ago

Ah, just realised this is actually a duplicate of #97!