如何从NX项目构建独立可执行脚本?
我有一个NX项目,该项目具有我想部署的后端模块。我的问题是,在编译后,node_modules
文件夹变为巨大,而Heroku拒绝了我的部署。
我尝试删除node_modules
文件夹,因为我认为在编译项目后,我将不再需要它了。
我运行node main.js
之后发生了什么:
Error: Cannot find module 'tslib'
Require stack:
- /dist/apps/backend/main.js
at Function.Module._resolveFilename (node:internal/modules/cjs/loader:933:15)
at Function.Module._load (node:internal/modules/cjs/loader:778:27)
at Module.require (node:internal/modules/cjs/loader:1005:19)
at require (node:internal/modules/cjs/helpers:102:18)
at Object.752 (/dist/apps/backend/main.js:2:898496)
at __webpack_require__ (/dist/apps/backend/main.js:2:898874)
at /dist/apps/backend/main.js:2:899067
at /dist/apps/backend/main.js:2:899812
at Object.<anonymous> (/dist/apps/backend/main.js:2:900044)
at Module._compile (node:internal/modules/cjs/loader:1105:14) {
code: 'MODULE_NOT_FOUND',
requireStack: [ '/dist/apps/backend/main.js' ]
事实证明,我已经编译了我已编译(带有WebPack)的main.js
仍然需要一些外部依赖性。
如何配置不需要node_modules
?的汇编
I have an Nx project that has a backend module that I'd like to deploy. My problem is that after compilation the node_modules
folder becomes huge and Heroku rejects my deployment.
I tried deleting the node_modules
folder because I thought that after compiling the project I'm not gonna need it anymore.
What happened after I ran node main.js
was this:
Error: Cannot find module 'tslib'
Require stack:
- /dist/apps/backend/main.js
at Function.Module._resolveFilename (node:internal/modules/cjs/loader:933:15)
at Function.Module._load (node:internal/modules/cjs/loader:778:27)
at Module.require (node:internal/modules/cjs/loader:1005:19)
at require (node:internal/modules/cjs/helpers:102:18)
at Object.752 (/dist/apps/backend/main.js:2:898496)
at __webpack_require__ (/dist/apps/backend/main.js:2:898874)
at /dist/apps/backend/main.js:2:899067
at /dist/apps/backend/main.js:2:899812
at Object.<anonymous> (/dist/apps/backend/main.js:2:900044)
at Module._compile (node:internal/modules/cjs/loader:1105:14) {
code: 'MODULE_NOT_FOUND',
requireStack: [ '/dist/apps/backend/main.js' ]
As it turns out this main.js
that I've compiled (with Webpack) still needs some external dependencies.
How can I configure a compilation that does not need node_modules
?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
没有node_modules,您将无法运行项目。
运行应用程序时,需要在根路径和DIST文件夹处将Node_Modules放置。
看起来应该这样:
You can't run your project without the node_modules.
When you run your app, you need to have the node_modules at the root path and your dist folder.
It should look like this :