gpt4 book ai didi

json - npm run build > 不在 NestJs 项目中创建 dist 文件夹

转载 作者:行者123 更新时间:2023-12-03 23:35:58 48 4
gpt4 key购买 nike

我尝试使用 npm run start:prod 开始我的项目命令但得到

Error: Cannot find module {path to my project}\dist\main.js' .

我试图将项目中所有文件的路径从 src/myController 重命名为 ../myController 。

我的 package.json(脚本)

"scripts": {
"build": "tsc -p tsconfig.build.json",
"format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\"",
"start": "ts-node -r tsconfig-paths/register src/main.ts",
"start:dev": "concurrently \"wait-on dist/main.js && nodemon\" \"tsc -w -p tsconfig.json\" ",
"start:debug": "nodemon --config nodemon-debug.json",
"prestart:prod": "rimraf dist && npm run build",
"start:prod": "node dist/main.js"

我的 tsconfig.json
{
"compilerOptions": {
"module": "commonjs",
"declaration": true,
"noImplicitAny": false,
"removeComments": true,
"allowSyntheticDefaultImports": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"target": "es6",
"sourceMap": true,
"rootDir": ".",
"outDir": "../dist",
"baseUrl": "./src"
},
"include": [ "./src/**/*.ts", ],
"exclude": ["node_modules", "dist", "src/**/*.spec.ts", "src/**/__test__/*"]
}

实际输出:

nest-typescript-starter@1.0.0 prestart:prod {path to my project} rimraf dist && npm run build

nest-typescript-starter@1.0.0 build {path to my project} tsc -p tsconfig.build.json

nest-typescript-starter@1.0.0 start:prod {path to my project} node dist/main.js



内部/模块/cjs/loader.js:584
抛出错误;
^

Error: Cannot find module {path to my project}\dist\main.js'

最佳答案

好吧,我有点傻。答案很简单。在 package.json 中,您需要从 "start:prod": "node dist/main.js" 更改行至"start:prod": "node dist/src/main.js" .在 tsconfig.json 你需要改变 "outDir": "../dist""outDir": "./dist"

关于json - npm run build > 不在 NestJs 项目中创建 dist 文件夹,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56790991/

48 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com