Hi Team,
I’m using React Template, we would like to remove the extension dependency during import, but we are unable to achieve
My .babelrc file
{
"presets": ["@babel/preset-env", "@babel/preset-react"],
"plugins": [
[
"module-resolver",
{
"root": ["./src"],
"extensions": [".js", ".jsx"],
"alias": {
"@": "./src"
}
}
]
]
}
No Error:
import HelloUser from “@/components/HelloUser.jsx”
Got Error:
import HelloUser from “@/components/HelloUser”
this module-resolver helps to set the import alias as expected, but for the extension, I’m getting the following error,
Module not found: Error: Can’t resolve ‘./components/HelloUser’ in ‘D:\projects\Freshworks\Global\recurring-ticket\sdk\src’
resolve ‘./components/HelloUser’ in ‘D:\projects\Freshworks\Global\recurring-ticket\sdk\src’
using description file: D:\projects\Freshworks\Global\recurring-ticket\sdk\package.json (relative path: ./src)
Field ‘browser’ doesn’t contain a valid alias configuration
using description file: D:\projects\Freshworks\Global\recurring-ticket\sdk\package.json (relative path: ./src/components/HelloUser)
no extension
Field ‘browser’ doesn’t contain a valid alias configuration
D:\projects\Freshworks\Global\recurring-ticket\sdk\src\components\HelloUser doesn’t exist
.js