TSC 不会在不同的系统上编译



我在打字稿中创建了一个节点应用程序。当我在本地运行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,节点,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"
}
}

TSCONFIG:

{
"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文件。
  • 不要部署打字稿文件,这会向远程代码库添加大量代码。

错误

  • 此错误表示某些 TS 规则未应用于本地 TS。
  • 我注意到rootDir./app,你已经包括为/app.也许它正在寻找/app下的/app文件夹。尝试以 root 身份./,看看是否可以修复它。顺便说一句,我是OvernightJS的创建者,我强烈建议您在部署之前转译所有代码。

最新更新