vue2使用pnpm编译打包时的错误处理

1. 错误信息

error in ./src/views/forest/forestGateway.vue?vue&type=script&lang=js Module parse failed: Unexpected token (203:39) 
File was processed with these loaders: * ./node_modules/.pnpm/**cache-loader**@4.1.0_webpack@4.47.0/node_modules/cache-loader/dist/cjs.js * ./node_modules/.pnpm/vue-loader@15.11.1_@vue+compiler-sfc@3.5.21_cache-loader@4.1.0_webpack@4.47.0__css-load_5a3c64a85473ede7d9205802ebc6db0e/node_modules/vue-loader/lib/index.js You may need an additional loader to handle the result of these loaders. | console.log('getUserMemoryInfo', res) | if (+res.code === 200) { > this.topBarActive = res.data?.[0]?.memoryValue ? res.data[0].memoryValue : this.topBarActive | const bottomToggle = this.stringToBool(res.data?.[1]?.memoryValue) | const flexStyle = this.topBarActive && !bottomToggle ? 1 : 'inherit' @ ./src/views/forest/forestGateway.vue?vue&type=script&lang=js 1:0-380 1:396-399 1:401-778 1:401-778 @ ./src/views/forest/forestGateway.vue @ ./src/router/index.js @ ./src/main.js @ multi ./src/main.js

2. 没有配置合适的loader,在vue.config.js里面配置

module.exports = {
  transpileDependencies: [
    '@ct/component-gallery-tracking-sdk',
    '@ct/bwtools', 
    '@ct/china-tower-tech-components-v2', 
    '@ct/lentoid-player',
    'markmap-common', 
    'markmap-view', 
    'markmap-lib', 
    'yaml',
    'marked',
    '@vscode',
    '@ct/ais-js-kit',
    'cache-loader' // <-- 新增
  ],
  lintOnSave: false,
  devServer: {
其他忽略

3. 清除缓存

rmdir /s /q node_modules\.cache
pnpm store prune

4. 重新安装依赖并打包

pnpm install
pnpm build

这样就可以了,这个模块用了es2020的语法,需要用babel-loader转成es2015

posted @ 2025-09-15 22:14  猝死的路上  阅读(75)  评论(0)    收藏  举报