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

Problems with module resolution in nitro #612

Closed
itpropro opened this issue Oct 25, 2022 · 8 comments
Closed

Problems with module resolution in nitro #612

itpropro opened this issue Oct 25, 2022 · 8 comments
Assignees

Comments

@itpropro
Copy link
Contributor

itpropro commented Oct 25, 2022

Environment

Node: 16.18
nitropack: latest
Windows 11 22H2 (but also tested in WSL Ubuntu)

Reproduction

https://github.com/itpropro/nitro-repro

Describe the bug

I am getting multiple bugs with the mongodb library, but I don't really know what they are caused by. Some, like the one in the reproduction repository are occuring in dev and production (after build), but some are only occuring after the app was build and is run with node.
The reproduction repo was the most minimal setup I could reproduce one of the errors with. They all seem so be connected to the mongodb-connection-string-url package (https://www.npmjs.com/package/mongodb-connection-string-url).
To reproduce the error mongodb_connection_string_url_1.default is not a constructor, just execute pnpm i and pnpm dev and make a POST request to http://localhost:3000/test/123. It should result in this:

mongodb_connection_string_url_1.default is not a constructor

  at parseOptions (/E:/repos/nitro-repro/.nitro/dev/index.mjs:13354:19)
  at new MongoClient (/E:/repos/nitro-repro/.nitro/dev/index.mjs:19297:64)
  at /E:/repos/nitro-repro/.nitro/dev/index.mjs:20952:29
  at /E:/repos/nitro-repro/.nitro/dev/index.mjs:635:47
  at processTicksAndRejections (node:internal/process/task_queues:96:5)
  at async Object.handler (/E:/repos/nitro-repro/.nitro/dev/index.mjs:682:19)
  at async Server.toNodeHandle (/E:/repos/nitro-repro/.nitro/dev/index.mjs:732:7)

with a real application, I get this error with production builds (not in dev):

[nitro] [request error] [unhandled] URL.install is not a function
  at Object.<anonymous> (E:\repos\project\api\.output\server\node_modules\whatwg-url\index.js:8:5)
  at Module._compile (node:internal/modules/cjs/loader:1155:14)
  at Object.Module._extensions..js (node:internal/modules/cjs/loader:1209:10)
  at Module.load (node:internal/modules/cjs/loader:1033:32)
  at Function.Module._load (node:internal/modules/cjs/loader:868:12)
  at Module.require (node:internal/modules/cjs/loader:1057:19)
  at require (node:internal/modules/cjs/helpers:103:18)
  at Object.<anonymous> (E:\repos\project\api\.output\server\node_modules\mongodb-connection-string-url\lib\index.js:4:22)
  at Module._compile (node:internal/modules/cjs/loader:1155:14)
  at Object.Module._extensions..js (node:internal/modules/cjs/loader:1209:10)
[nitro] [dev] [unhandledRejection] TypeError: URL.install is not a function

Additional context

Maybe related to https://stackoverflow.com/questions/72718506/nuxt-js-3-application-with-mongoose-mongodb-not-starting-in-production

Logs

No response

@itpropro itpropro changed the title Multiple problems with mongodb Multiple problems with mongodb library in nitro Oct 25, 2022
@itpropro
Copy link
Contributor Author

itpropro commented Oct 31, 2022

Any idea or starting point I can pivot from @pi0 or @danielroe ? I'm pretty much blocked at this point after trying every possible rollup plugin config and tsconfig combination for days 😄

@itpropro
Copy link
Contributor Author

itpropro commented Nov 7, 2022

In addition, this problem seems to appear with many external libraries. E.g. the @azure/identity library works fine in dev as well, but when built, it throws and error with [nitro] [dev] [unhandledRejection] TypeError: coreTracing.createSpanFunction is not a function or [nitro] [dev] [unhandledRejection] TypeError: coreTracing.createTracingClient is not a function.
I can create another reproduction for this specific example, but I think it is a more general problem, as problems like these appear with many external libraries. Can I provide any more information that would help you with this issue @pi0 ?

EDIT: I created a new minimal reproduction branch (azure-identity): https://github.com/itpropro/nitro-repro/tree/azure-identity
Just execute pnpm install, pnpm run build && pnpm run start and make a get request to http://localhost:3000/test and the coreTracing.createSpanFunction is not a function error should appear.

@pi0 pi0 self-assigned this Nov 16, 2022
@itpropro itpropro changed the title Multiple problems with mongodb library in nitro Problems with module resolution in nitro Nov 26, 2022
@itpropro
Copy link
Contributor Author

Any updates @pi0 ?

@victorberland

This comment was marked as duplicate.

@manniL
Copy link
Contributor

manniL commented Nov 30, 2022

Does this by any chance relate to unjs/jiti#87?

@itpropro
Copy link
Contributor Author

The issue is still existent with the current nitropack-edge version (^2.0.0-27847631.8186a02):

image

@itpropro
Copy link
Contributor Author

itpropro commented Jan 29, 2023

I still have the same problems, even after #782 was merged.

None of them occur with nitro dev, but with nitro build and running it, I still get errors like:

coreTracing.createSpanFunction is not a function

With the trace being

[nitro] [request error] [unhandled] coreTracing.createSpanFunction is not a function
  at Object.<anonymous> (E:\repos\project\.output\server\node_modules\@azure\app-configuration\dist\index.js:2053:32)
  at Module._compile (node:internal/modules/cjs/loader:1159:14)
  at Module._extensions..js (node:internal/modules/cjs/loader:1213:10)
  at Module.load (node:internal/modules/cjs/loader:1037:32)
  at Module._load (node:internal/modules/cjs/loader:878:12)
  at ModuleWrap.<anonymous> (node:internal/modules/esm/translators:169:29)
  at ModuleJob.run (node:internal/modules/esm/module_job:193:25)
  at async Promise.all (index 0)
  at async ESMLoader.import (node:internal/modules/esm/loader:530:24)
  at async Object.handler (/E:/repos/project/.output/server/chunks/node-server.mjs:455:19)
[nitro] [dev] [unhandledRejection] TypeError: coreTracing.createSpanFunction is not a function

Any idea @pi0?

@itpropro
Copy link
Contributor Author

itpropro commented Feb 7, 2023

Fixed by #909, thanks for the great work @pi0 🙏

@itpropro itpropro closed this as completed Feb 7, 2023
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.

4 participants