问题描述
在nest build
或nest build --webpack
之后,dist文件夹不包含所有必需的模块,并且在尝试运行node main.js
时得到了Error: Cannot find module '@nestjs/core'
.
After nest build
or nest build --webpack
dist folder does not contain all required modules and I got Error: Cannot find module '@nestjs/core'
when trying to run node main.js
.
我在 https://docs.nestjs.com/上找不到任何明确的说明正确构建用于生产的应用程序,所以也许我错过了一些东西?
I could not find any clear instructions on https://docs.nestjs.com/ on how to correctly build app for production, so maybe I missed something?
推荐答案
开箱即用,巢状cli不支持将node_modules
依赖项包含在dist
捆绑包中.
Out of the box, nest cli does not support including the node_modules
dependencies into the dist
bundle.
但是,有一些自定义Webpack配置的社区示例,其中包括捆绑软件中的依赖项,例如捆绑的巢.如此问题所述,有必要包含将未使用的动态库列入白名单.
However, there are some community examples of custom webpack configs that include the dependencies in the bundle, e.g. bundled-nest. As described in this issue, it is necessary to include the webpack.IgnorePlugin
to whitelist unused dynamic libraries.
这篇关于如何使用捆绑包中的node_modules依赖关系正确构建用于生产的NestJS应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!