我正在尝试从这样的文件中导入.tsx
组件:.ts
src/index.ts:
import { Icon } from './components/Icon/Icon';
但我收到了这个错误:
./src/index.ts
Module not found: Can't resolve './components/Icon/Icon' in '/Applications/project/src'
这些是代码的导入部分:
src/components/Icon/Icon.tsx:
export class Icon extends Component<Props> {
/* component code here */
}
webpack.config.js:
/* code */
resolve: {
extensions: ['.js', '.json', '.ts', '.tsx'],
},
/* more code */
{
test: /\.jsx?$/,
exclude: /node_modules/,
use: 'babel-loader',
},
{
test: /\.tsx?$/,
exclude: /node_modules/,
use: [
{
loader: 'awesome-typescript-loader',
options: {
query: {
declaration: false,
},
},
},
],
},
和tsconfig.json
:
{
"compilerOptions": {
"module": "commonjs",
"target": "es5",
"allowSyntheticDefaultImports": true,
"sourceMap": true,
"jsx": "react",
"esModuleInterop": true,
"resolveJsonModule": true,
"strictFunctionTypes": true,
"noImplicitReturns": true,
"suppressImplicitAnyIndexErrors": true,
"noUnusedLocals": true,
"alwaysStrict": true,
"moduleResolution": "node",
"declaration": true,
"strictNullChecks": true
},
"include": ["src/**/*"],
"exclude": ["node_modules", "**/*.spec.ts", "**/*.spec.tsx"]
}