Как использовать aliases с typescript + webpack?
Получаю ошибку: Cannot find module '@components/test' or its corresponding type declarations.
// tsconfig.json
{
"compilerOptions": {
"target": "es5", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', or 'ESNEXT'. */
"module": "commonjs", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', 'es2020', or 'ESNext'. */ /* Report errors in .js files. */
"jsx": "react", /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */ /* Specify file to store incremental compilation information */
"removeComments": true, /* Do not emit comments to output. */
"strict": true, /* Enable all strict type-checking options. */ /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */
"baseUrl": "src", /* Base directory to resolve non-absolute module names. */
"paths": {
"@components/*": ["components/*"]
},
"esModuleInterop": true, /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */
"skipLibCheck": true, /* Skip type checking of declaration files. */
"forceConsistentCasingInFileNames": true /* Disallow inconsistently-cased references to the same file. */
}
}
// webpack.config.js
alias: {
'@components': path.resolve(__dirname, 'src', 'components'),
'@containers': path.resolve(__dirname, 'src', 'containers'),
}
Ответы (1 шт):
Автор решения: NocteFury
→ Ссылка
Возможно это связано с тем, что .ts файлв не знают, к какому tsconfig.json они относятся.
В tsconfig.json нужно указать files и include, чтобы этот tsconfig использовался для работы с ts файлами.