mpvue TypeError: Cannot read property 'indexOf' of undefined

0yg35tkg  于 5个月前  发布在  其他
关注(0)|答案(5)|浏览(54)

[问题简单描述]

问题复现步骤:

这是我在移植 SPA 到 mpvue 的时候出现的,其它环境恐怕难以复现。

  1. 运行 npm run dev

期望的表现:

不报错

观察到的表现:

出现一个报错,但是编译成功。

控制台输出:

TypeError: Cannot read property 'indexOf' of undefined
    at Resolver.parse (C:\Users\vimcaw\Documents\Work\kcshop-mpvue\node_modules\enhanced-resolve\lib\Resolver.js:181:28)
    at Resolver.<anonymous> (C:\Users\vimcaw\Documents\Work\kcshop-mpvue\node_modules\enhanced-resolve\lib\ParsePlugin.js:15:25)
    at Resolver.applyPluginsAsyncSeriesBailResult1 (C:\Users\vimcaw\Documents\Work\kcshop-mpvue\node_modules\tapable\lib\Tapable.js:256:13)
    at runNormal (C:\Users\vimcaw\Documents\Work\kcshop-mpvue\node_modules\enhanced-resolve\lib\Resolver.js:130:20)
    at Resolver.doResolve (C:\Users\vimcaw\Documents\Work\kcshop-mpvue\node_modules\enhanced-resolve\lib\Resolver.js:116:3)
    at Resolver.<anonymous> (C:\Users\vimcaw\Documents\Work\kcshop-mpvue\node_modules\enhanced-resolve\lib\UnsafeCachePlugin.js:37:12)
    at Resolver.applyPluginsAsyncSeriesBailResult1 (C:\Users\vimcaw\Documents\Work\kcshop-mpvue\node_modules\tapable\lib\Tapable.js:256:13)
    at runNormal (C:\Users\vimcaw\Documents\Work\kcshop-mpvue\node_modules\enhanced-resolve\lib\Resolver.js:130:20)
    at Resolver.doResolve (C:\Users\vimcaw\Documents\Work\kcshop-mpvue\node_modules\enhanced-resolve\lib\Resolver.js:116:3)
    at Resolver.resolve (C:\Users\vimcaw\Documents\Work\kcshop-mpvue\node_modules\enhanced-resolve\lib\Resolver.js:86:14)
    at resolve (C:\Users\vimcaw\Documents\Work\kcshop-mpvue\node_modules\webpack\lib\NormalModule.js:133:14)
    at Promise (C:\Users\vimcaw\Documents\Work\kcshop-mpvue\node_modules\@f-loat\mpvue-loader\lib\mp-compiler\index.js:254:7)
    at new Promise (<anonymous>)
    at Promise.all.Object.keys.map.k (C:\Users\vimcaw\Documents\Work\kcshop-mpvue\node_modules\@f-loat\mpvue-loader\lib\mp-compiler\index.js:253:12)
    at Array.map (<anonymous>)
    at resolveSrc (C:\Users\vimcaw\Documents\Work\kcshop-mpvue\node_modules\@f-loat\mpvue-loader\lib\mp-compiler\index.js:252:52)

进去源码后发现是 Resolver.prototype.parse 的参数 identifierundefined 导致的,进一步到父级,发现 ParsePlugin.prototype.apply 函数处理到某项时 request.requestundefined ,输出这个 request 的值为:

{ 
  context: {},
  path: 'C:\\Users\\vimcaw\\Documents\\Work\\kcshop-mpvue\\src',
  request: undefined
}

屏幕截图和动态 GIF 图

relj7zay

relj7zay1#

@vimcaw 最好能提供个 demo 复现

sqserrrh

sqserrrh2#

issue超过30天无更新或响应,7天后将自动关闭,如果问题状态有更新请及时更新issue

nnsrf1az

nnsrf1az3#

我也出现了这个问题,当我这样引入组件的时候,修改一下引入方式就不报错了。

components: {
    appTitle: require('@/components/app-title.vue').default
  }

相关问题