I'm migrating from Webpack to Parcel and I use folder aliases like this in my component:
import * as authActions from 'actions/authActions';
I get this error: Cannot find module 'actions/authActions'
The weird thing is, it only shows when using build
, it works in development mode but not in production.
I've set up my aliases in package.json like the docs say:
{
"scripts: {
"build-client": "parcel build client/index.html dist/client",
"build-server": "parcel build server/index.js --target node -d dist/server",
"build-test": "yarn build-server && node ./dist/server/index.js"
},
"alias": {
"actions": "./client/actions"
}
}
It's a server-side rendered app, I'm importing the component in different places and I can't use the default Parcel root, because it's relative to the entry file.
How can I get this to properly resolve aliases?
This question was asked when parcel1 was the current version, so for anyone arriving here in the future, it's worth pointing out that Parcel 2 supports this through glob aliases
Your package.json
would include an entry like this:
{
"alias": {
"actions/*": "./client/actions/$1"
}
}
Then, to import all the exports of ./client/actions/authActions
, you could write:
import * as authActions from "actions/authActions";
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With