SimonAlling / userscripter

Create userscripts in a breeze!
https://www.npmjs.com/package/userscripter
MIT License
100 stars 10 forks source link

Build error `Error in bail mode: Error: callback(): The callback was already called` and how to mitigate #94

Open hlovdal opened 1 year ago

hlovdal commented 1 year ago

TL;DR

If you get error Error in bail mode: Error: callback(): The callback was already called when running npm run build then you need to set the NODE_OPTIONS environment variable to include --openssl-legacy-provider.

Details

I created a test project by running node .../src/github/userscripter/bin/cli.js init followed by running npm install and npm run build, and the build command failed with

ℹ 「atl」: Using tsconfig.json from .../userscript/test1/tsconfig.json
Error in bail mode: Error: callback(): The callback was already called.
    at context.callback (.../userscript/test1/node_modules/loader-runner/lib/LoaderRunner.js:106:10) Error: callback(): The callback was already called.
    at context.callback (.../userscript/test1/node_modules/loader-runner/lib/LoaderRunner.js:106:10)

After making some debug modifications to node_modules/loader-runner/lib/LoaderRunner.js I noticed the following in the debug output

    error: ModuleParseError: Module parse failed: error:0308010C:digital envelope routines::unsupported
    File was processed with these loaders:
     * ./node_modules/awesome-typescript-loader/dist/entry.js
     * ./node_modules/restrict-imports-loader/dist/index.js
    You may need an additional loader to handle the result of these loaders.
    Error: error:0308010C:digital envelope routines::unsupported
        at new Hash (node:internal/crypto/hash:71:19)
        at Object.createHash (node:crypto:130:10)
        at module.exports (.../userscript/test1/node_modules/webpack/lib/util/createHash.js:135:53)
        at NormalModule._initBuildHash (.../userscript/test1/node_modules/webpack/lib/NormalModule.js:417:16)
        at handleParseResult (.../userscript/test1/node_modules/webpack/lib/NormalModule.js:477:10)
        at .../userscript/test1/node_modules/webpack/lib/NormalModule.js:500:6
        at .../userscript/test1/node_modules/webpack/lib/NormalModule.js:358:12
        ...

which matched the part about "digital envelope routines::unsupported" from this comment, and when I ran

env NODE_OPTIONS=--openssl-legacy-provider npm run build

then the build succeeded.

$ npm --version
9.6.0
$ node --version
v16.18.1
SimonAlling commented 1 year ago

Awesome! That's been a major pain point for me as well lately. I don't remember exactly what the context was, but the next time I face this error, I'll keep this issue in mind!

SimonAlling commented 1 year ago

Yeah, this happens with Node 18 and 20 btw, but not with Node 16.