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';
Add resolve.alias in webpack configuration
resolve : {
alias: {
// 这里配置没有问题, jsx中可以正常使用
"@utils": "./src/utils"
}
}
Referenced in jsx (can be used)
import { toFieldValue } from '@utils/tools'
{
"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
}
}
Webpack adds configuration (webpackConfig is the configuration of webpack)
webpackConfig.resolve.plugins = [(new TsConfigPathsPlugin({
configFileName: "tsconfig.json",
compiler: "typescript",
}))];
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
Solved~
tool.js must declare a corresponding tool.d.ts file.
Drunk, drunk~~~