hotwired / stimulus

A modest JavaScript framework for the HTML you already have
https://stimulus.hotwired.dev/
MIT License
12.73k stars 426 forks source link

Supporting Node.js 18 is helpful #728

Closed sanak closed 9 months ago

sanak commented 1 year ago

I tried yarn install on my M1 Mac (macOS: Sonoma 14.0) Node.js 18.18.0 + npm 9.8.1 environment, but it failed with the following error.

% yarn install
yarn install v1.22.19
[1/4] 🔍  Resolving packages...
[2/4] 🚚  Fetching packages...
[3/4] 🔗  Linking dependencies...
warning " > ts-loader@9.4.3" has incorrect peer dependency "webpack@^5.0.0".
[4/4] 🔨  Building fresh packages...
[1/2] ⡀ core-js
warning Error running install script for optional dependency: "/Users/sanak/Build/js/stimulus/node_modules/watchpack-chokidar2/node_modules/fsevents: Command failed.
Exit code: 1
Command: node install.js
Arguments: 
Directory: /Users/sanak/Build/js/stimulus/node_modules/watchpack-chokidar2/node_modules/fsevents
Output:
node:events:495
      throw er; // Unhandled 'error' event
      ^

Error: spawn node-gyp ENOENT
    at ChildProcess._handle.onexit (node:internal/child_process:284:19)
    at onErrorNT (node:internal/child_process:477:16)
    at process.processTicksAndRejections (node:internal/process/task_queues:82:21)
Emitted 'error' event on ChildProcess instance at:
    at ChildProcess._handle.onexit (node:internal/child_process:290:12)
    at onErrorNT (node:internal/child_process:477:16)
    at process.processTicksAndRejections (node:internal/process/task_queues:82:21) {
  errno: -2,
  code: 'ENOENT',
  syscall: 'spawn node-gyp',
  path: 'node-gyp',
  spawnargs: [ 'rebuild' ]
}

Node.js v18.18.0"
✨  Done in 6.71s.

I also tried yarn start and yarn test after that, but those also failed.

"yarn start" result ```zsh % yarn start yarn run v1.22.19 $ concurrently "npm:watch" "npm:start:examples" [start:examples] [start:examples] > @hotwired/stimulus@3.2.2 start:examples [start:examples] > cd examples && yarn install && node server.js [start:examples] [watch] [watch] > @hotwired/stimulus@3.2.2 watch [watch] > rollup -wc [watch] [1/4] Resolving packages... success Already up-to-date. [watch] rollup v2.53.1 [watch] bundles src/index.js → dist/stimulus.umd.js, dist/stimulus.js... [start:examples] Listening on http://localhost:9000/ [start:examples] Browserslist: caniuse-lite is outdated. Please run: [start:examples] npx browserslist@latest --update-db [start:examples] [start:examples] Why you should do it regularly: [start:examples] https://github.com/browserslist/browserslist#browsers-data-updating [watch] created dist/stimulus.umd.js, dist/stimulus.js in 1.2s [watch] bundles src/index.js → dist/stimulus.min.js... [start:examples] node:internal/crypto/hash:69 [start:examples] this[kHandle] = new _Hash(algorithm, xofLen); [start:examples] ^ [start:examples] [start:examples] Error: error:0308010C:digital envelope routines::unsupported [start:examples] at new Hash (node:internal/crypto/hash:69:19) [start:examples] at Object.createHash (node:crypto:133:10) [start:examples] at module.exports (/Users/sanak/Build/js/stimulus/examples/node_modules/webpack/lib/util/createHash.js:135:53) [start:examples] at NormalModule._initBuildHash (/Users/sanak/Build/js/stimulus/examples/node_modules/webpack/lib/NormalModule.js:417:16) [start:examples] at handleParseError (/Users/sanak/Build/js/stimulus/examples/node_modules/webpack/lib/NormalModule.js:471:10) [start:examples] at /Users/sanak/Build/js/stimulus/examples/node_modules/webpack/lib/NormalModule.js:503:5 [start:examples] at /Users/sanak/Build/js/stimulus/examples/node_modules/webpack/lib/NormalModule.js:358:12 [start:examples] at /Users/sanak/Build/js/stimulus/examples/node_modules/loader-runner/lib/LoaderRunner.js:373:3 [start:examples] at iterateNormalLoaders (/Users/sanak/Build/js/stimulus/examples/node_modules/loader-runner/lib/LoaderRunner.js:214:10) [start:examples] at iterateNormalLoaders (/Users/sanak/Build/js/stimulus/examples/node_modules/loader-runner/lib/LoaderRunner.js:221:10) { [start:examples] opensslErrorStack: [ 'error:03000086:digital envelope routines::initialization error' ], [start:examples] library: 'digital envelope routines', [start:examples] reason: 'unsupported', [start:examples] code: 'ERR_OSSL_EVP_UNSUPPORTED' [start:examples] } [start:examples] [start:examples] Node.js v18.18.0 [start:examples] npm run start:examples exited with code 1 [watch] created dist/stimulus.min.js in 1s ```
"yarn test" result ```zsh % yarn test yarn run v1.22.19 $ yarn build:test && karma start karma.conf.cjs $ tsc -b tsconfig.test.json 12 10 2023 21:01:56.313:ERROR [karma-server]: UnhandledRejection: Error: error:0308010C:digital envelope routines::unsupported at new Hash (node:internal/crypto/hash:69:19) at Object.createHash (node:crypto:133:10) at module.exports (/Users/sanak/Build/js/stimulus/node_modules/webpack/lib/util/createHash.js:135:53) at Compilation.createHash (/Users/sanak/Build/js/stimulus/node_modules/webpack/lib/Compilation.js:1918:16) at /Users/sanak/Build/js/stimulus/node_modules/webpack/lib/Compilation.js:1386:9 at AsyncSeriesHook.eval [as callAsync] (eval at create (/Users/sanak/Build/js/stimulus/node_modules/tapable/lib/HookCodeFactory.js:33:10), :6:1) at AsyncSeriesHook.lazyCompileHook (/Users/sanak/Build/js/stimulus/node_modules/tapable/lib/Hook.js:154:20) at Compilation.seal (/Users/sanak/Build/js/stimulus/node_modules/webpack/lib/Compilation.js:1342:27) at /Users/sanak/Build/js/stimulus/node_modules/webpack/lib/Compiler.js:675:18 at /Users/sanak/Build/js/stimulus/node_modules/webpack/lib/Compilation.js:1261:4 12 10 2023 21:01:56.314:ERROR [karma-server]: Error: error:0308010C:digital envelope routines::unsupported at new Hash (node:internal/crypto/hash:69:19) at Object.createHash (node:crypto:133:10) at module.exports (/Users/sanak/Build/js/stimulus/node_modules/webpack/lib/util/createHash.js:135:53) at Compilation.createHash (/Users/sanak/Build/js/stimulus/node_modules/webpack/lib/Compilation.js:1918:16) at /Users/sanak/Build/js/stimulus/node_modules/webpack/lib/Compilation.js:1386:9 at AsyncSeriesHook.eval [as callAsync] (eval at create (/Users/sanak/Build/js/stimulus/node_modules/tapable/lib/HookCodeFactory.js:33:10), :6:1) at AsyncSeriesHook.lazyCompileHook (/Users/sanak/Build/js/stimulus/node_modules/tapable/lib/Hook.js:154:20) at Compilation.seal (/Users/sanak/Build/js/stimulus/node_modules/webpack/lib/Compilation.js:1342:27) at /Users/sanak/Build/js/stimulus/node_modules/webpack/lib/Compiler.js:675:18 at /Users/sanak/Build/js/stimulus/node_modules/webpack/lib/Compilation.js:1261:4 { opensslErrorStack: [ 'error:03000086:digital envelope routines::initialization error' ], library: 'digital envelope routines', reason: 'unsupported', code: 'ERR_OSSL_EVP_UNSUPPORTED' } error Command failed with exit code 1. info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command. ```

When I switched Node.js to v16, then all of above commands were no problem.

% rm -rf node_modules
% asdf local nodejs 16.20.2
% yarn install
yarn install v1.22.19
[1/4] 🔍  Resolving packages...
[2/4] 🚚  Fetching packages...
[3/4] 🔗  Linking dependencies...
warning " > ts-loader@9.4.3" has incorrect peer dependency "webpack@^5.0.0".
[4/4] 🔨  Building fresh packages...
✨  Done in 12.05s.
% yarn start
:
[start:examples]     + 8 hidden modules
[start:examples] ℹ 「wdm」: Compiled successfully.
:
# Stop by [Ctrl+C] after checking localhost:9000
% yarn test
yarn run v1.22.19
:
Chrome Headless 118.0.5993.70 (Mac OS 10.15.7): Executed 214 of 214 SUCCESS (5.896 secs / 5.003 secs)
TOTAL: 214 SUCCESS
✨  Done in 10.52s.

But Node.js 16 reached EOL (https://endoflife.date/nodejs) at 2023-09-11, so supporting Node.js 18 is really helpful. 🙇‍♂️