首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >项目编译后找不到模块

项目编译后找不到模块
EN

Stack Overflow用户
提问于 2018-11-16 10:23:49
回答 1查看 1.1K关注 0票数 0

这是我的package.json:

代码语言:javascript
复制
   {
      "main": "./build/app.js",
      "types": "./build/app.d.ts",
      "scripts": {
        "start": "tsc && node build/app.js",
        "dev": "concurrently \"tsc -w \" \"nodemon ./build/app.js\"",
        "lint": "tslint ./src"
      },
    }

tsconfig.json:

代码语言:javascript
复制
{
  "compilerOptions": {
     "target": "es6",
     "module": "commonjs",
     "outDir": "build",
     "sourceMap": true,
     "declaration": true,
     "moduleResolution": "node",
     "allowSyntheticDefaultImports": true,
     "experimentalDecorators": true,
     "baseUrl": "src",
  },
  "files": [
     "./node_modules/@types/node/index.d.ts"
  ],
  "include": [
     "src/**/*.ts"
  ]
}

Error: Cannot find module 'controllers/index'。我试图像这样导入这个文件:import controllers from 'controllers/index' in app.ts。

项目结构形象

那么,如何将相对路径添加到编译文件夹"build"?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-11-16 10:27:21

尝试使用模块别名。

解决这个问题的方法有很多,例如https://www.npmjs.com/package/module-alias。或者如果你用Webpack,他们也有这个功能,只是谷歌的"webpack别名“。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/53335860

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档