Невозможно импортировать файлы `.tsx` из файлов` .ts` - PullRequest
0 голосов
/ 11 января 2019

Я пытаюсь импортировать .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 / компоненты / Икона / 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"]
}

...