如何为我的打字稿项目从脚本创建dist / app.js

问题描述 投票:-1回答:1

我正在使用node + express + type-srcipt项目。我运行npm run build,一切正常,但是当我运行npm run start时,出现此错误。

@ruler-mobility/[email protected] start /Users/macbook/Desktop/ruler
> npm run serve


> @ruler-mobility/[email protected] serve /Users/macbook/Desktop/ruler
> node dist/app.js

npm ERR! code ELIFECYCLE
 npm ERR! errno 1
 npm ERR! @ruler-mobility/[email protected] serve: `node dist/app.js`
 npm ERR! Exit status 1
 npm ERR! 
 npm ERR! Failed at the @ruler-mobility/[email protected] serve script.
 npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

 npm ERR! A complete log of this run can be found in:
 npm ERR!     /Users/macbook/.npm/_logs/2020-02-21T20_53_55_009Z-debug.log
 npm ERR! code ELIFECYCLE
 npm ERR! errno 1
 npm ERR! @ruler-mobility/[email protected] start: `npm run serve`
 npm ERR! Exit status 1
 npm ERR! 
 npm ERR! Failed at the @ruler-mobility/[email protected] start script.
 npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

 npm ERR! A complete log of this run can be found in:
 npm ERR!     /Users/macbook/.npm/_logs/2020-02-21T20_53_55_045Z-debug.log

注意:标尺是项目的名称。

我在packag.json中的脚本是这样设置的:

 "scripts": {
    "start": "npm run serve",
    "build": "npm run build-source",
    "serve": "node dist/app.js",
    "watch-node": "nodemon dist/app.js",
    "watch": "concurrently -k -p \"[{name}]\" -n \"TypeScript,Node\" -c \"cyan.bold,green.bold\" \"npm run watch-source\" \"npm run watch-node\"",
    "build-source": "webpack",
    "watch-source": "webpack -w",
    "debug": "npm run build && npm run watch-debug",
    "serve-debug": "nodemon --inspect dist/app.js",
    "watch-debug": "concurrently -k -p \"[{name}]\" -n \"TypeScript,Node\" -c \"cyan.bold,green.bold\" \"npm run watch-source\" \"npm run serve-debug\"",
    "lint": "eslint \"**/*.{js,jsx,ts,tsx}\" --quiet --fix",
    "test": "jest --forceExit --coverage --verbose",
    "watch-test": "npm run test -- --watchAll",
    "stop-win": "Taskkill /IM node.exe /F",
    "stop-linux": "killall node"
},   

这是我的tscongfig.json文件:

{
"compilerOptions": {
    "alwaysStrict": true,
    "module": "commonjs",
    "esModuleInterop": true,
    "allowSyntheticDefaultImports": true,
    "jsx": "react",
    "lib": ["es6", "dom"],
    "target": "es6",
    "noImplicitAny": true,
    "moduleResolution": "node",
    "sourceMap": true,
    "outDir": "dist",
    "baseUrl": ".",
    "paths": {
        "*": ["node_modules/*"],
        "@ruler": ["src", "packages"],
        "@ruler/*": ["src/*", "packages/*"],
        "@ruler/configs": ["configs"],
        "@ruler/configs/*": ["configs/*"],
        "@ruler/test": ["test"],
        "@ruler/test/*": ["test/*"],
        "@ruler/types": ["types"],
        "@ruler/types/*": ["types/*"]
    }
},
"exclude": ["node_modules", "**/*.spec.ts"]
}

我是打字稿的开始者,有人可以告诉我如何运行我的项目吗?

谢谢。

typescript npm configuration config npm-scripts
1个回答
0
投票

似乎问题在于webpack在何处构建项目。如果删除dist并运行npm run build,然后检查dist是否存在,这将告诉您构建任务是否将输出放入dist

© www.soinside.com 2019 - 2024. All rights reserved.