Home  >  Q&A  >  body text

javascript - Webpack resolve.alias does not work with typescript?

environment:

- node v6.9.2
- typescript v2.4.1
- webpack v1.15.0
- awesome-typescript-loader v3.2.1

question:

Report an error in tsx Module not found 'tools'...

import { toFieldValue } from '@utils/tools';

resolve : {
    alias: { 
        // 这里配置没有问题, jsx中可以正常使用
         "@utils": "./src/utils"
    }
}
import { toFieldValue } from '@utils/tools'

tsx configuration

{
  "compilerOptions": {
    "outDir": "./dist/",
    "module": "commonjs",
    "target": "es6",
    "sourceMap": true,
    "allowSyntheticDefaultImports": true,
    "jsx": "react",
    "pretty": true,
    "noImplicitAny": true,
    "traceResolution": true,
    "baseUrl": ".",
    "paths": {
      "@utils/*": ["./src/utils/*"]
    },
    "lib": [
      "dom",
      "es2015.promise",
      "es5",
      "es2015.iterable",
      "es2015.generator",
      "es2015.symbol",
      "es7"]
  },
  "include": [
    "./src/**/*"
  ],
  "exclude": [
    "node_modules"
  ],
  "awesomeTypescriptLoaderOptions": {
    "useBabel": true,
    "useCache": true
  }
}
我想大声告诉你我想大声告诉你2664 days ago1100

reply all(2)I'll reply

  • 習慣沉默

    習慣沉默2017-07-05 10:38:58

    It should be possible to use alias. The author can refer to my react-typescript template project, https://github.com/devlee/tpl...

    This doesn’t work for the poster. The reason is that the paths in tsconfig should be paths, not source files directly

    reply
    0
  • 过去多啦不再A梦

    过去多啦不再A梦2017-07-05 10:38:58

    Solved~
    tool.js must declare a corresponding tool.d.ts file.
    Drunk, drunk~~~

    reply
    0
  • Cancelreply