nitro icon indicating copy to clipboard operation
nitro copied to clipboard

project fails to import uuid package

Open pi0 opened this issue 3 years ago • 2 comments

Environment

Operating System: Linux Node Version: v17.1.0 Nuxt Version: 3.0.0-27319101.3e82f0f Package Manager: [email protected] Bundler: Vite User Config: - Runtime Modules: - Build Modules: -

Reproduction

  1. Add server/api/test.ts
import { v4 } from "uuid";

export default () => {
  return v4();
};

Describe the bug

Building the project causes the package uuid to fail to be imported. The problem does not exist when running the dev server.

Cannot find module '/home/me/dev/nuxt3-app/.output/server/node_modules/uuid/wrapper.mjs' imported from /home/me/dev/nuxt3-app/.output/server/chunks/test.mjs
  at new NodeError (node:internal/errors:371:5)  
  at finalizeResolution (node:internal/modules/esm/resolve:394:11)  
  at moduleResolve (node:internal/modules/esm/resolve:915:10)  
  at defaultResolve (node:internal/modules/esm/resolve:1005:11)  
  at ESMLoader.resolve (node:internal/modules/esm/loader:475:30)  
  at ESMLoader.getModuleJob (node:internal/modules/esm/loader:245:18)  
  at ModuleWrap.<anonymous> (node:internal/modules/esm/module_job:79:40)  
  at link (node:internal/modules/esm/module_job:78:36)

Additional context

Moved from https://github.com/nuxt/framework/issues/2371

Logs

No response

pi0 avatar Apr 12 '22 17:04 pi0

Happens for ws v8 too.

dargmuesli avatar Jul 13 '22 07:07 dargmuesli

I debugged a bit and saw that at https://github.com/unjs/nitro/blob/feebf8f6fda08873452c826e89327db380a495c7/src/rollup/plugins/externals.ts#L147 only .js and .json files are returned. https://github.com/vercel/nft however seems like it works with .mjs files and like it can detect an exports.import statement, as the one by ws, too...

I'm not that used to low level packages like these, so that's where my understanding left for now.

dargmuesli avatar Jul 13 '22 23:07 dargmuesli

latest version of nitro seems inlining uuid

pi0 avatar May 16 '24 17:05 pi0