node.js 项目构建问题及解决
前言 今天在编译构建一个 node.js 项目时,在构建过程中遇到了一些问题,本文将记录问题及对应的解决方案。 问题 1 在执行 npm run build 遇到此提示: error Expected linebreaks to be 'LF' but found 'CRLF' linebreak-style 根据信息可以看出是 eslint 的报错,查看 .eslintrc.js 文件,修改 linebreak-style 对应的行: 'linebreak-style': ['error', process.platform === 'win32' ? 'windows' : 'unix'], 重新运行命令,顺利构建成功。 这个问题的原因是项目的作者可能是使用 Linux 或 Mac 构建的,没有考虑 Windows 的情况,通过这行配置,可以根据运行的环境来决定 lint 规则。 问题 2 在执行 npm start 遇到了第二个问题: Generating browser application bundles (phase: building)...node:internal/crypto/hash:79 this[kHandle] = new _Hash(algorithm, xofLen, algorithmId, getHashCache()); ^ Error: error:0308010C:digital envelope routines::unsupported at new Hash (node:internal/crypto/hash:79:19) at Object.createHash (node:crypto:139:10) at BulkUpdateDecorator.hashFactory (D:\code\xx\node_modules\webpack\lib\util\createHash.js:145:18) at BulkUpdateDecorator.update (D:\code\xx\node_modules\webpack\lib\util\createHash.js:46:50) at RawSource.updateHash (D:\code\xx\node_modules\webpack\node_modules\webpack-sources\lib\RawSource.js:77:8) at NormalModule._initBuildHash (D:\code\xx\node_modules\webpack\lib\NormalModule.js:880:17) at handleParseResult (D:\code\xx\node_modules\webpack\lib\NormalModule.js:946:10) at D:\code\xx\node_modules\webpack\lib\NormalModule.js:1040:4 at processResult (D:\code\xx\node_modules\webpack\lib\NormalModule.js:755:11) at D:\code\xx\node_modules\webpack\lib\NormalModule.js:819:5 { opensslErrorStack: [ 'error:03000086:digital envelope routines::initialization error', 'error:0308010C:digital envelope routines::unsupported' ], library: 'digital envelope routines', reason: 'unsupported', code: 'ERR_OSSL_EVP_UNSUPPORTED' } 根据这个报错,推测可能是啥 hash 算法不支持,通过查阅相关资料,得到以下解决方案: ...