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

IITM Throws Error When an NPM Package is Not Installed in the Root Folder #97

Closed
aryamohanan opened this issue Jun 10, 2024 · 7 comments · Fixed by #108
Closed

IITM Throws Error When an NPM Package is Not Installed in the Root Folder #97

aryamohanan opened this issue Jun 10, 2024 · 7 comments · Fixed by #108

Comments

@aryamohanan
Copy link

I am encountering an issue while using prisma module in my test folder along with the import-in-the-middle. When attempting to import the prisma module from a subdirectory, I receive the following error:

node:internal/process/esm_loader:40
internalBinding('errors').triggerUncaughtException(
^
Error: Cannot find module '.prisma/client/default'
Require stack:
/prismabug/node_modules/import-in-the-middle/lib/get-exports.js
/prismabug/node_modules/import-in-the-middle/hook.js
at Module._resolveFilename (node:internal/modules/cjs/loader:1134:15)
at Function.resolve (node:internal/modules/helpers:188:19)
at /prismabug/node_modules/import-in-the-middle/lib/get-exports.js:26:33)
at Array.map ()
at getFullCjsExports (/prismabug/node_modules/import-in-the-middle/lib/get-exports.js:23:40)
at getExports (/prismabug/node_modules/import-in-the-middle/lib/get-exports.js:76:12)
at async processModule (/prismabug/node_modules/import-in-the-middle/hook.js:131:23)
at async getSource (/prismabug/node_modules/import-in-the-middle/hook.js:249:23)
at async load (/prismabug/node_modules/import-in-the-middle/hook.js:280:26)
at async nextLoad (node:internal/modules/esm/hooks:864:22) {
code: 'MODULE_NOT_FOUND',
requireStack: [
'/prismabug/node_modules/import-in-the-middle/lib/get-exports.js',
'/prismabug/node_modules/import-in-the-middle/hook.js'
]

This occurs when I install and use the prisma package in a subdirectory. Notably, the issue only arises with Node.js version 18.19 and above. Versions 18 and below do not exhibit this problem. Additionally, the issue does not occur when the import-in-the-middle hook is not used.

If I add the prismato the root package.json, the error does not occur. However, due to project compliance, I am not allowed to include the the package in the root directory.

Expected Behavior

The prisma package should be successfully imported and executed without errors.
When I run the command node --loader ./hook.mjs packages/a/test/prisma/app.mjs it should not throw any error.

Actual Behavior

The error Cannot find module '.prisma/client/default' is thrown.

Steps to Reproduce the Problem

  1. Unzip prismabug.zip.
  2. Run npm i.
  3. Navigate to the Prisma test directory: cd packages/a/test/prisma/
  4. Run npm i within this directory.
  5. Return to the root directory: cd ../../../../
  6. Execute the following command
    node --loader ./hook.mjs packages/a/test/prisma/app.mjs
    or
    node --import ./register packages/a/test/prisma/app.mjs
    both are throwing errors.

Specifications

  • Version: 1.8.0
  • Platform: arm64
  • Subsystem: Node 18.19
@timfish
Copy link
Contributor

timfish commented Jun 10, 2024

I'm currently looking into this!

Related:
getsentry/sentry-javascript#12325

@aryamohanan
Copy link
Author

@timfish Thank you for responding promptly. Looking forward to your updates.

@timfish
Copy link
Contributor

timfish commented Jun 12, 2024

As Prisma is CJS, I think this is fixed by #96 but I need to confirm.

@aryamohanan
Copy link
Author

Hello @timfish

I just used the latest version 1.8.1, but the issue still persists. I am now encountering the following error:

Error: 'import-in-the-middle' failed to wrap 'file:///artifacts/packages/collector/test/tracing/database/prisma/node_modules/@prisma/client/default.js'
at getSource (/artifacts/packages/core/node_modules/import-in-the-middle/hook.js:304:21)
at async load (/artifacts/packages/core/node_modules/import-in-the-middle/hook.js:319:26)
at async nextLoad (node:internal/modules/esm/hooks:866:22)
at async Hooks.load (node:internal/modules/esm/hooks:449:20)
at async MessagePort.handleMessage (node:internal/modules/esm/worker:196:18) {
cause: TypeError: emitImportAssertionWarning is not a function
at defaultLoad (node:internal/modules/esm/load:119:5)
at nextLoad (node:internal/modules/esm/hooks:866:28)
at getExports (/artifacts/packages/core/node_modules/import-in-the-middle/lib/get-exports.js:80:27)
at processModule (/artifacts/packages/core/node_modules/import-in-the-middle/hook.js:131:29)
at getSource (/artifacts/packages/core/node_modules/import-in-the-middle/hook.js:269:31)
at load (/artifacts/packages/core/node_modules/import-in-the-middle/hook.js:319:32)
at nextLoad (node:internal/modules/esm/hooks:866:28)
at Hooks.load (node:internal/modules/esm/hooks:449:26)
at MessagePort.handleMessage (node:internal/modules/esm/worker:196:24)
at [nodejs.internal.kHybridDispatch] (node:internal/event_target:825:20)
}
import { PrismaClient } from '@prisma/client';
^^^^^^^^^^^^
SyntaxError: The requested module '@prisma/client' does not provide an export named 'PrismaClient'
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 asyncRunEntryPointWithESMLoader (node:internal/modules/run_main:123:5)

@timfish
Copy link
Contributor

timfish commented Jun 19, 2024

A warning is logged to the console but it no longer throws.

#108 actually fixes the prisma issue

@aryamohanan
Copy link
Author

@timfish, could you please let me know when the fix is released? Thank you.

@jsumners-nr
Copy link
Contributor

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

Successfully merging a pull request may close this issue.

3 participants