【发布时间】:2020-09-02 18:35:20
【问题描述】:
我正在尝试设置一个 Typescript 项目并且在编译该项目时遇到了困难。我已将 outDir 属性设置为当前文件夹中的 dist。我尝试运行build: echo \"Hello\" and pwd 以及正确输出hello 的npm run build,以及tsconfig.json 所在的当前目录。
我的 tsconfig.json 是:
{
"compilerOptions": {
"baseUrl": "src",
"declaration": true,
"lib": ["esnext.asynciterable", "es6", "es2017"],
"module": "commonjs",
"moduleResolution": "node",
"outDir": "./dist/",
"strict": true,
"noUnusedLocals": true,
"noImplicitReturns": true,
"forceConsistentCasingInFileNames": true,
"target": "es2017",
"typeRoots": ["./node_modules/@types", "./@types"]
},
"include": [
"./src/**/*.ts"
]
}
我的 package.json 是:
"scripts": {
"build": "npm run compile",
"compile": "tsc",
"clean": "rm -rf node_modules dist"
},
"devDependencies": {
"@types/node": "^11.13.4",
"typescript": "^3.6.4"
}
在我的目录中的任何地方或看起来的任何地方都没有创建 dist 文件夹。对于我的目录中的一个 ts 文件,命令行上似乎没有任何错误,也没有我传递给 tsc 的任何其他特定文件选项。我是不是初始化不正确?
【问题讨论】:
-
您可以尝试删除
baseUrl并检查它是否解决了问题? -
我试过了,但还是不行。虽然我确实尝试运行 npm run compile,然后它能够编译并创建 dist 文件夹,但不确定为什么 build 没有运行。
标签: typescript npm tsc