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

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

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

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/*"
  ]
}
node.js typescript heroku npm tsc
1个回答
0
投票

在本地运行tsc并部署构建的.js文件。不想部署打字稿文件,这将为您的远程代码库添加很多代码。但是无论如何,此错误意味着某些操作系统无法应用到您的本地操作系统。我注意到rootDir是./app,并且您已经包含了/ app。也许是在/ app下寻找/ app文件夹。以root身份尝试./,看看是否可以解决。顺便说一句,我是OvernightJS的创建者,我强烈建议您在部署之前先转换所有代码。

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