TSC 不会在不同的系统上编译
TSC won't compile on different systems
我用打字稿创建了一个节点应用程序。当我在本地 运行 tsc 时,一切正常,我可以 运行 该应用程序。但是当我在 heroku 上部署时,它给我编译错误:
app/api/controllers/ingredient.controller.ts(3,24): error TS2307: Cannot find module '../schemas/ingredient.schema'.
app/api/controllers/ingredient.controller.ts(23,13): error TS7006: Parameter 'units' implicitly has an 'any' type.
app/api/controllers/ingredient.controller.ts(30,42): error TS7006: Parameter 'result' implicitly has an 'any' type.
app/api/controllers/ingredient.controller.ts(37,70): error TS7006: Parameter 'result' implicitly has an 'any' type.
app/api/controllers/ingredient.controller.ts(44,70): error TS7006: Parameter 'result' implicitly has an 'any' type.
奇怪的是,我确保所有版本都相同:NPM、Node、TSC ...
我有一个 TSConfig 被拾取并使用。我还应该去哪里看看?
版本:
> node -v && npm -v && tsc -v && tsc
v13.3.0
6.13.1
Version 3.7.3
Package.json:
{
"name": "server",
"version": "1.0.0",
"description": "",
"main": "build/app.js",
"scripts": {
"tsc": "node -v && npm -v && tsc -v && tsc",
"watch-ts": "tsc -w",
"watch-node": "nodemon build/app.js",
"watch": "docker-compose up -d && concurrently -k -p \"[{name}]\" -n \"TypeScript, Node\" -c \"yello.bold, cyan.bold\" \"yarn run watch-ts\" \"yarn run watch-node\"",
"start": "node build/app.js",
"build": "npm run tsc"
},
"author": "",
"license": "ISC",
"dependencies": {
"@overnightjs/core": "^1.6.9",
"@overnightjs/logger": "^1.1.9",
"@types/body-parser": "^1.17.1",
"@types/cors": "^2.8.6",
"@types/dotenv": "^8.2.0",
"@types/express": "^4.17.2",
"@types/mongodb": "^3.3.11",
"@types/mongoose": "^5.5.32",
"@types/multer": "^1.3.10",
"concurrently": "^5.0.0",
"cors": "^2.8.5",
"dotenv": "^8.2.0",
"mongoose": "^5.7.13",
"multer": "^1.4.2",
"nodemon": "^2.0.1",
"typescript": "^3.7.3"
},
"engines": {
"node": "13.3.0",
"npm": "6.13.1"
}
}
TS配置:
{
"compilerOptions": {
"target": "es6", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019' or 'ESNEXT'. */
"module": "commonjs", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */
"outDir": "build", /* Redirect output structure to the directory. */
"rootDir": "./app", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */
"importHelpers": true, /* Import emit helpers from 'tslib'. */
"strict": true, /* Enable all strict type-checking options. */
"noImplicitAny": true, /* Raise error on expressions and declarations with an implied 'any' type. */
/* Module Resolution Options */
"moduleResolution": "node", /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */
"baseUrl": "./", /* Base directory to resolve non-absolute module names. */
"typeRoots": [ /* List of folders to include type definitions from. */
"node_modules/@types"
],
"types": ["node"], /* Type declaration files to be included in compilation. */
"esModuleInterop": true, /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */
/* Experimental Options */
"experimentalDecorators": true, /* Enables experimental support for ES7 decorators. */
"emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */
/* Advanced Options */
"forceConsistentCasingInFileNames": true /* Disallow inconsistently-cased references to the same file. */
},
"include": [
"app/*"
]
}
建议
- 运行 在本地执行 tsc 并部署构建的 .js 文件。
- 不要部署 typescript 文件,这会向您的远程代码库添加大量代码。
错误
- 此错误意味着某些 ts 规则未应用于您的本地 ts。
- 我注意到
rootDir
是 ./app
,而您已包含 /app
。也许它正在寻找 /app
下的 /app
文件夹。以 root 身份尝试 ./
,看看是否可以解决问题。顺便说一句,我是 OvernightJS
的创建者,我强烈建议您在部署之前转换所有代码。
我用打字稿创建了一个节点应用程序。当我在本地 运行 tsc 时,一切正常,我可以 运行 该应用程序。但是当我在 heroku 上部署时,它给我编译错误:
app/api/controllers/ingredient.controller.ts(3,24): error TS2307: Cannot find module '../schemas/ingredient.schema'.
app/api/controllers/ingredient.controller.ts(23,13): error TS7006: Parameter 'units' implicitly has an 'any' type.
app/api/controllers/ingredient.controller.ts(30,42): error TS7006: Parameter 'result' implicitly has an 'any' type.
app/api/controllers/ingredient.controller.ts(37,70): error TS7006: Parameter 'result' implicitly has an 'any' type.
app/api/controllers/ingredient.controller.ts(44,70): error TS7006: Parameter 'result' implicitly has an 'any' type.
奇怪的是,我确保所有版本都相同:NPM、Node、TSC ...
我有一个 TSConfig 被拾取并使用。我还应该去哪里看看?
版本:
> node -v && npm -v && tsc -v && tsc
v13.3.0
6.13.1
Version 3.7.3
Package.json:
{
"name": "server",
"version": "1.0.0",
"description": "",
"main": "build/app.js",
"scripts": {
"tsc": "node -v && npm -v && tsc -v && tsc",
"watch-ts": "tsc -w",
"watch-node": "nodemon build/app.js",
"watch": "docker-compose up -d && concurrently -k -p \"[{name}]\" -n \"TypeScript, Node\" -c \"yello.bold, cyan.bold\" \"yarn run watch-ts\" \"yarn run watch-node\"",
"start": "node build/app.js",
"build": "npm run tsc"
},
"author": "",
"license": "ISC",
"dependencies": {
"@overnightjs/core": "^1.6.9",
"@overnightjs/logger": "^1.1.9",
"@types/body-parser": "^1.17.1",
"@types/cors": "^2.8.6",
"@types/dotenv": "^8.2.0",
"@types/express": "^4.17.2",
"@types/mongodb": "^3.3.11",
"@types/mongoose": "^5.5.32",
"@types/multer": "^1.3.10",
"concurrently": "^5.0.0",
"cors": "^2.8.5",
"dotenv": "^8.2.0",
"mongoose": "^5.7.13",
"multer": "^1.4.2",
"nodemon": "^2.0.1",
"typescript": "^3.7.3"
},
"engines": {
"node": "13.3.0",
"npm": "6.13.1"
}
}
TS配置:
{
"compilerOptions": {
"target": "es6", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019' or 'ESNEXT'. */
"module": "commonjs", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */
"outDir": "build", /* Redirect output structure to the directory. */
"rootDir": "./app", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */
"importHelpers": true, /* Import emit helpers from 'tslib'. */
"strict": true, /* Enable all strict type-checking options. */
"noImplicitAny": true, /* Raise error on expressions and declarations with an implied 'any' type. */
/* Module Resolution Options */
"moduleResolution": "node", /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */
"baseUrl": "./", /* Base directory to resolve non-absolute module names. */
"typeRoots": [ /* List of folders to include type definitions from. */
"node_modules/@types"
],
"types": ["node"], /* Type declaration files to be included in compilation. */
"esModuleInterop": true, /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */
/* Experimental Options */
"experimentalDecorators": true, /* Enables experimental support for ES7 decorators. */
"emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */
/* Advanced Options */
"forceConsistentCasingInFileNames": true /* Disallow inconsistently-cased references to the same file. */
},
"include": [
"app/*"
]
}
建议
- 运行 在本地执行 tsc 并部署构建的 .js 文件。
- 不要部署 typescript 文件,这会向您的远程代码库添加大量代码。
错误
- 此错误意味着某些 ts 规则未应用于您的本地 ts。
- 我注意到
rootDir
是./app
,而您已包含/app
。也许它正在寻找/app
下的/app
文件夹。以 root 身份尝试./
,看看是否可以解决问题。顺便说一句,我是OvernightJS
的创建者,我强烈建议您在部署之前转换所有代码。