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

Cannot build with Node v20 #417

Closed
shamas opened this issue Oct 9, 2023 · 3 comments · Fixed by #418
Closed

Cannot build with Node v20 #417

shamas opened this issue Oct 9, 2023 · 3 comments · Fixed by #418
Labels
good first issue Good for newcomers

Comments

@shamas
Copy link

shamas commented Oct 9, 2023

Note that node v20 won't compile due to nodejs/node#47880

Might want to add a <20.0.0 to the package. Or just close this to have a record if someone encounters the issue.

Build error

$ npm i && npm run build
npm WARN EBADENGINE Unsupported engine {
npm WARN EBADENGINE   package: '[email protected]',
npm WARN EBADENGINE   required: { node: '>=16.0.0 <20.0.0', npm: '>=8.0.0' },
npm WARN EBADENGINE   current: { node: 'v20.8.0', npm: '10.1.0' }
npm WARN EBADENGINE }

up to date, audited 735 packages in 763ms

97 packages are looking for funding
  run `npm fund` for details

4 vulnerabilities (3 moderate, 1 high)

To address all issues, run:
  npm audit fix

Run `npm audit` for details.

> [email protected] build
> npm run __prepare-folder && npm run __check-types && NODE_ENV=production ts-node --esm build.ts


> [email protected] __prepare-folder
> rimraf dist && copyfiles LICENSE manifest.json dist && copyup public/images/icon128.png public/* dist && cp -R public/themes dist


> [email protected] __check-types
> tsc --noEmit

TypeError [ERR_UNKNOWN_FILE_EXTENSION]: Unknown file extension ".ts" for /Users/shamas/MonoLabs/taska/projects/my-notes-copy/build.ts
    at new NodeError (node:internal/errors:406:5)
    at Object.getFileProtocolModuleFormat [as file:] (node:internal/modules/esm/get_format:99:9)
    at defaultGetFormat (node:internal/modules/esm/get_format:142:36)
    at defaultLoad (node:internal/modules/esm/load:120:20)
    at nextLoad (node:internal/modules/esm/hooks:833:28)
    at load (/Users/shamas/MonoLabs/taska/projects/my-notes-copy/node_modules/ts-node/dist/child/child-loader.js:19:122)
    at nextLoad (node:internal/modules/esm/hooks:833:28)
    at Hooks.load (node:internal/modules/esm/hooks:416:26)
    at MessagePort.handleMessage (node:internal/modules/esm/worker:168:24)
    at [nodejs.internal.kHybridDispatch] (node:internal/event_target:807:20) {
  code: 'ERR_UNKNOWN_FILE_EXTENSION'
}
@penge
Copy link
Owner

penge commented Oct 9, 2023

Thanks for sharing. I'll update it to <20, or >=20 (and npm >=10).

To make the build work in Node 20, we create:

// register.js
import { register } from "node:module";
import { pathToFileURL } from "node:url";

register("ts-node/esm", pathToFileURL("./build.ts"));

And then we update:

"build": "npm run __prepare-folder && npm run __check-types && NODE_ENV=production node --import ./register.js ./build.ts"

Running the build should now work. (other unrelated scripts will need updating too)

@penge penge added the good first issue Good for newcomers label Oct 9, 2023
@shamas
Copy link
Author

shamas commented Oct 9, 2023

Verified that fix as described is working 👍

@penge
Copy link
Owner

penge commented Oct 16, 2023

Hi @shamas

just to let you know, My Notes now uses Node 20, and all packages have been updated (typescript, esbuild, jest,...).

Feel free to Fork the project :)

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

Successfully merging a pull request may close this issue.

2 participants