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

Why i got multiple js file, and Cannot find module './indexes' ? #1189

Open
seepine opened this issue May 9, 2024 · 4 comments
Open

Why i got multiple js file, and Cannot find module './indexes' ? #1189

seepine opened this issue May 9, 2024 · 4 comments
Labels
question Further information is requested

Comments

@seepine
Copy link

seepine commented May 9, 2024

I ncc a fastify project with typeorm, run ncc build app.ts -o dist and like this

$ npm run ncc

> fastify-template-ts@1.0.0 ncc
> ncc build app.ts -o dist

ncc: Version 0.38.1
ncc: Compiling file index.js into CJS
ncc: Using typescript@5.4.5 (local user-provided)
   0kB  dist/file.js
   1kB  dist/worker-pipeline.js
   1kB  dist/worker.js
   5kB  dist/worker1.js
7024kB  dist/index.js
7031kB  [5705ms] - ncc 0.38.1
image

And try run node index.js

$ node index.js

node:internal/event_target:1088
  process.nextTick(() => { throw err; });
                           ^
Error: Cannot find module './indexes'
Require stack:
- /Users/seepine/workspace/test-transfer/dist/worker1.js
    at Module._resolveFilename (node:internal/modules/cjs/loader:1144:15)
    at Module._load (node:internal/modules/cjs/loader:985:27)
    at Module.require (node:internal/modules/cjs/loader:1235:19)
    at require (node:internal/modules/helpers:176:18)
    at Object.<anonymous> (/Users/seepine/workspace/test-transfer/dist/worker1.js:5:37)
    at Module._compile (node:internal/modules/cjs/loader:1376:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1435:10)
    at Module.load (node:internal/modules/cjs/loader:1207:32)
    at Module._load (node:internal/modules/cjs/loader:1023:12)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:135:12)
Emitted 'error' event on Worker instance at:
    at [kOnErrorMessage] (node:internal/worker:326:10)
    at [kOnMessage] (node:internal/worker:337:37)
    at MessagePort.<anonymous> (node:internal/worker:232:57)
    at [nodejs.internal.kHybridDispatch] (node:internal/event_target:814:20)
    at exports.emitMessage (node:internal/per_context/messageport:23:28) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [ '/Users/seepine/workspace/test-transfer/dist/worker1.js' ]
}

Node.js v20.10.0
@styfle
Copy link
Member

styfle commented May 11, 2024

Its hard to know without the source code. Usually this is caused by a dynamic require.

You can check in /Users/seepine/workspace/test-transfer/dist/worker1.js for something like require(str) and change it to require('./indexes') perhaps.

@styfle styfle added the question Further information is requested label May 11, 2024
@seepine
Copy link
Author

seepine commented May 11, 2024

ncc build app.ts -o dist

Hi, try index.ts

import fastify from "fastify";
const server = fastify({});

server.listen({
  host: "0.0.0.0",
  port: 3000
});
pnpm i fastify
pnpm i @vercel/ncc -D

Add scripts to package.json

"ncc": "ncc build index.ts -o dist-ncc"

And run

pnpm ncc

@navnair
Copy link

navnair commented Jul 25, 2024

@seepine Hi, Did you manage to figure this out? I'm experiencing the same issue.

@seepine
Copy link
Author

seepine commented Aug 5, 2024

@seepine Hi, Did you manage to figure this out? I'm experiencing the same issue.

No,i gave up on NCC.

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

No branches or pull requests

3 participants