我正在从Webpack迁移到Parcel,并在我的组件中使用了如下文件夹别名:
import * as authActions from 'actions/authActions';我得到这个错误:Cannot find module 'actions/authActions'
奇怪的是,它只在使用build时显示,它在开发模式下工作,但在生产模式下不起作用。
我在package.json中设置了我的别名,比如the docs:
{
"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"
}
}这是一个服务器端渲染的应用程序,我在不同的位置导入组件,不能使用默认的Parcel根目录,因为它是相对于入口文件的。
如何才能正确地解析别名?
发布于 2021-10-20 17:14:25
这个问题是在parcel1是当前版本时提出的,因此对于将来来到这里的任何人来说,值得指出的是,宗地2通过glob aliases支持此功能
您的package.json将包含如下条目:
{
"alias": {
"actions/*": "./client/actions/$1"
}
}然后,要导入所有导出的./client/actions/authActions,您可以这样写:
import * as authActions from "actions/authActions";https://stackoverflow.com/questions/54052884
复制相似问题