penge / my-notes

Simple and fast note-taking in Chrome with Google Drive support.
https://chrome.google.com/webstore/detail/my-notes/lkeeogfaiembcblonahillacpaabmiop
MIT License
240 stars 34 forks source link

Cannot build with Node v20 #417

Closed shamas closed 11 months ago

shamas commented 11 months ago

Note that node v20 won't compile due to https://github.com/nodejs/node/issues/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: 'my-notes@3.26.0',
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.

> my-notes@3.26.0 build
> npm run __prepare-folder && npm run __check-types && NODE_ENV=production ts-node --esm build.ts

> my-notes@3.26.0 __prepare-folder
> rimraf dist && copyfiles LICENSE manifest.json dist && copyup public/images/icon128.png public/* dist && cp -R public/themes dist

> my-notes@3.26.0 __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 commented 11 months ago

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)

shamas commented 11 months ago

Verified that fix as described is working 👍

penge commented 11 months ago

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 :)