tsconfig无法从外部目录导入打字稿文件

时间:2019-04-17 17:02:08

标签: javascript reactjs typescript express nodemon

我正在使用nodemon启动服务器,这是一个基本的nextJS应用程序,带有使用tsconfig的打字稿。运行nodemon命令:

ts-node -r dotenv/config --project tsconfig.server.json src/server/index.ts

有效,索引文件或src/server/目录中的任何文件中的打字稿均有效。但是,在其中的某些文件中,我是从src/otherDirectory/stuff.ts导入文件的,导入时它会告诉我错误-您可能需要适当的加载程序来处理此文件类型。

这是我设置的tsconfig。我很困惑,因为我没有指定tsconfig只在一个目录中运行。 TS在服务器目录中工作...但是如果我从另一个目录导入相同文件,则不会

tsconfig

{
  "compileOnSave": false,
  "compilerOptions": {
    "noEmit": true,
    "target": "esnext",
    "module": "esnext",
    "jsx": "preserve",
    "allowJs": true,
    "moduleResolution": "node",
    "allowSyntheticDefaultImports": true,
    "noUnusedLocals": true,
    "noUnusedParameters": true,
    "removeComments": false,
    "preserveConstEnums": true,
    "sourceMap": true,
    "skipLibCheck": true,
    "resolveJsonModule": true,
    "baseUrl": ".",
    "typeRoots": ["./node_modules/@types"],
    "lib": ["dom", "es2015", "es2016"],
    "outDir": ".next"
  },
  "include": ["typings/**/*.ts", "./bin/**/*"],
  "exclude": [".next"]
}

tsconfig.server

{
  "extends": "./tsconfig.json",
  "compilerOptions": {
    "noEmit": false,
    "module": "commonjs",
    "target": "es2017",
    "lib": ["es2017"],
    "outDir": ".next/server"
  },
  "include": ["typings/**/*.ts"],
  "exclude": [".next"]
}

0 个答案:

没有答案