babel-plugin-module-resolver
babel-plugin-module-resolver copied to clipboard
Problem with aliases
Babel resolver does not work in my next.js project
My .babelrc file
{
"presets": ["next/babel"],
"plugins": [
[
"module-resolver",
{
"root": ["./"],
"alias": {
"@components": "./src/components",
}
}
],
["styled-components", { "ssr": true }]
]
}
My tsconfig
"paths": {
"@components/*": ["./src/components/*"],
"baseUrl": "."
},
And when im trying to use it like that
import Login from '@components/login'
export default Login
vscode throws an error
Cannot find module '@components/login' or its corresponding type declarations.
I have the same error, Did you fix this?
Assume everything is correct- Perhaps try to restart TypeScript language server in vscode?
This worked for me:
- I removed
node_modules - yarn install
- pod install
- run
watchman watch-del-all && rm -rf $TMPDIR/react-native-packager-cache-* &&
rm -rf $TMPDIR/metro-bundler-cache-* && rm -rf node_modules/ && npm cache clean --force &&
npm install && npm start -- --reset-cache
And I use it like this
import { AppStateHandler, FocusListeners, LoadingContainer } from '@components';
This is TS2307. @kacluk123 it's good practice to include the error code, not just the text.
Anybody know how to fix it?
@MariusCatanoiu can you clarify what you mean? You were able to get this working?
This is TS2307. @kacluk123 it's good practice to include the error code, not just the text.
Anybody know how to fix it?
@MariusCatanoiu can you clarify what you mean? You were able to get this working?
I updated the previous comment