问题
事情是这样的,我建了一个dumi项目,准备写个组件,然后又在里面建了个examples文件夹起了个umi项目用来做测试,但是发现直接引入dumi中的组件报错了,错误信息如下:
Module parse failed: Unexpected token (6:8)
File was processed with these loaders:
* ./node_modules/umi/node_modules/@umijs/preset-built-in/bundled/@pmmmwh/react-refresh-webpack-plugin/loader/index.js
You may need an additional loader to handle the result of these loaders.
|
| export function Index(props) {
> return <div>
| 123
| </div>
@ ./src/pages/index.tsx 4:0-60 8:35-51
@ ./src/.umi/core/routes.ts
@ ./src/.umi/umi.ts
@ multi ./node_modules/umi/node_modules/@umijs/preset-built-in/bundled/@pmmmwh/react-refresh-webpack-plugin/client/ReactRefreshEntry.js ./src/.umi/umi.ts
解决
起初看这个报错信息也没看出啥问题来,后来想起以前写过一个相同架构的组件,打开那个项目看了下umi的用例多了一下的配置:
// .umirc.ts
...
chainWebpack: (memo) => {
memo.module.rule('ts-in-node_modules').include.clear();
return memo;
},
...
看git提交记录是专门用来解决这个问题的,而且还是我自己写的(属实有点离谱🤡),按照这个加上去果然就解决了。
然后也专门搜了下也没搜到相关内容,忘了当时是怎么解决的,所以特意记录一下。