为了在web项目中使用node.js模块,我使用了浏览器化v17.0.0。直到今天我尝试按以下方式转换src文件时,它才正常工作:
call browserify web-src.js -o web.js
Error: Can't walk dependency graph: ENOENT: no such file or directory, lstat '${home_dir}\process'
required by ${home_dir}\node_modules\mysql2\lib\pool.js
(非常奇怪,因为我没有更改浏览器化的版本或任何代码!)
过程模块存在于node_modules中,我已经尝试过清除npm缓存并使用npm install
完全重新安装。
如果禁用使用上述mysql2库的所有导入,则可以使用上述命令成功编译web.js。但是,当我试图向express.js web服务器提供此文件时,出现了一个错误:
Uncaught TypeError: Cannot read properties of undefined (reading 'split')
at Object.<anonymous> (web.js:122518)
at Object.<anonymous> (web.js:122527)
at Object.780../lib/telegram (web.js:122527)
at o (web.js:1)
at web.js:1
at Object.<anonymous> (web.js:171670)
at Object.<anonymous> (web.js:171981)
at Object.944.../database/database-functions (web.js:171981)
at o (web.js:1)
at web.js:1
它引用编译后的代码中的以下一行:
const majorVersion = parseInt(process.versions.node.split('.')[0]
发布于 2021-09-22 03:23:19
好的-我不应该尝试在浏览器上下文中使用node.js process。
结果是使用process导入模块的代码更改,这就是错误的表现方式。
奇怪的是,当导入mysql2包时,这阻止了编译。删除后,web.js编译,但电报API包导致运行时错误,也见上文。
https://stackoverflow.com/questions/69282911
复制相似问题