uuidjs / uuid

Generate RFC-compliant UUIDs in JavaScript
MIT License
14.65k stars 904 forks source link

[BUG] (v11) Unable to start Node.js app after build removed `wrapper.mjs` #820

Closed peterhirn closed 1 month ago

peterhirn commented 1 month ago

Before you begin...

Description of the problem

Unclear if this is a bug here or in vinxi

Recipe for reproducing

pnpm create solid@latest -s solid-start-uuid-v11

cd solid-start-uuid-v11
pnpm add uuid

Edit src/entry-server.tsx

import { v7 } from "uuid";
console.log(v7());
pnpm build
pnpm start
 ERROR  Cannot find module '/.../solid-start-uuid-v11/.output/server/node_modules/uuid/wrapper.mjs' imported from /.../solid-start-uuid-v11/.output/server/index.mjs              8:23:43 AM

  at finalizeResolution (node:internal/modules/esm/resolve:275:11)
  at moduleResolve (node:internal/modules/esm/resolve:932:10)
  at defaultResolve (node:internal/modules/esm/resolve:1056:11)
  at ModuleLoader.defaultResolve (node:internal/modules/esm/loader:650:12)
  at #cachedDefaultResolve (node:internal/modules/esm/loader:599:25)
  at ModuleLoader.resolve (node:internal/modules/esm/loader:582:38)
  at ModuleLoader.getModuleJobForImport (node:internal/modules/esm/loader:241:38)
  at ModuleJob._link (node:internal/modules/esm/module_job:132:49)

Additional information

pnpm dev works as expected.

Environment

Node: v23.1.0

Workaround

pnpm patch uuid

diff --git a/package.json b/package.json
index 12ea33f0527be28f3d263ef32b5a189882b46455..8475de8aea93583640cbb7ebfa966ed262e27635 100644
--- a/package.json
+++ b/package.json
@@ -29,7 +29,7 @@
       "node": {
         "module": "./dist/esm/index.js",
         "require": "./dist/cjs/index.js",
-        "import": "./wrapper.mjs"
+        "import": "./dist/esm/index.js"
       },
       "browser": {
         "import": "./dist/esm-browser/index.js",
broofa commented 1 month ago

Thanks for the report. I'm able to reproduce the issue. Looking into it.

broofa commented 1 month ago

@peterhirn So... technically I don't think this is an issue with uuid. Your error is complaining about there not being a "wrapper.mjs" in .output/server/node_modules/uuid, which is true...

$ ls .output/server/node_modules/uuid/wrapper.mjs
ls: .output/server/node_modules/uuid/wrapper.mjs: No such file or directory

... but the uuid package supplies that file, as seen in the top-level node_modules that pnpm installs:

$ ls node_modules/uuid/wrapper.mjs
node_modules/uuid/wrapper.mjs

So it looks like vinxi build is dropping that file on the floor for some reason.


That said, with the refactoring work that's gone into uuid@11, I'm not sure we need wrapper.mjs any more. I've opened #822 to look into removing it.

broofa commented 1 month ago

@peterhirn Fixed in #822, published in uuid@11.0.2. pnpm add uuid@latest should get you sorted out.

Note: It's still weird that vinxi isn't copying that wrapper.mjs file over, but probably not worth worrying about at this point.