简体   繁体   中英

Typescipt fails to recognize webpack resolve.alias

This is in my Webpack config:

usersAlias: path.resolve(__dirname, '../src/pages/users'),

This is in my tsconfig.json :

"baseUrl": ".",
"paths": {
  "usersAlias/*": ["src/pages/users/*"],
}

This is the code hierarchy:

解决方案

This is my usage in Àpp.js :

import Users from 'usersAlias/Users';

And this is the error I am getting:

Cannot find module 'usersAlias/Users'.ts(2307)

If I change Àpp.tsx to App.js Everything works! My issue is TypeScript related.

UPDATE

My Full tsconfig.json

{
  "compilerOptions": {
    "target": "es5",
    "lib": [
      "dom",
      "dom.iterable",
      "esnext"
    ],
    "allowJs": true,
    "skipLibCheck": true,
    "esModuleInterop": true,
    "allowSyntheticDefaultImports": true,
    "strict": true,
    "forceConsistentCasingInFileNames": true,
    "module": "esnext",
    "moduleResolution": "node",
    "resolveJsonModule": true,
    "isolatedModules": false,
    "noEmit": true,
    "jsx": "react"
  },
  "include": [
    "src"
  ],
  "baseUrl": ".",
  "paths": {
    "usersAlias/*": ["src/pages/users/*"],
  }
}

Maybe you dont need the ...

module.exports = {
  //...
  resolve: {
    alias: {
      users: path.resolve(__dirname, '/src/pages/users'),
    }
  }
};

And in your code

import Users from 'users';

Check config here

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM