没有 node_modules 文件夹就无法 运行 nestjs 构建

Can't run nestjs build without node_modules folder

我正在开发 Nestjs 微服务,需要使用以下命令 运行 在 dist 文件夹中构建并且工作正常

node dist/main.js

问题是,如果没有 node_modules 文件夹,上述命令将无法运行。为什么我们不能在没有 node_modules 文件夹的情况下 运行 构建文件夹 (dist)?

这是我遇到的错误

不,你不能。 Node.js 依赖于 package.json 来查找模块,这也依赖于 node_modules 来存储模块。也许你想把它编译成一个?试试这个 https://github.com/vercel/ncc。 Nest.js我从来没用过,不过你可以试试

这是 Node 代码,它使用 node_modules 文件夹来 搜索模块。 没有它就无法 运行。您可以尝试使用 pkg 之类的东西将其打包成可执行文件。 dist 文件夹只包含代码,不包含模块。