xlsx-style使用中常见问题及解决办法

问题1. Can't resolve './cptable' in 'xxx\node_modules_xlsx

在vue.config.js中引入以下代码

复制代码
configureWebpack: {
    externals: {
      './cptable': 'var cptable'
    },
  },

问题2. Can't resolve 'fs'

在vue.config.js中引入以下代码

复制代码
module.exports = defineConfig({
  transpileDependencies: true,
  configureWebpack: {
 
    externals: {
      './cptable': 'var cptable'
    },
    resolve: {
      fallback: {
        fs: false
      }
    },
  }
})

问题3:Can't resolve 'crypto'in D: code-a\LPA2 admin node modules (xlsx-style)

在vue.config.js中引入以下代码

复制代码
module.exports = defineConfig({
  transpileDependencies: true,
  configureWebpack: {
 
    externals: {
      './cptable': 'var cptable'
    },
    resolve: {
      fallback: {
        fs: false,
        crypto: false,
      }
    },
  }
})

问题4. jszip not a constructor

通过命令安装Webpack 插件
npm i node-polyfill-webpack-plugin -D

在vue.config.js中引入以下代码

复制代码
const NodePolyfillPlugin = require("node-polyfill-webpack-plugin")
 
module.exports = defineConfig({
  configureWebpack: {
    plugins: [
        new NodePolyfillPlugin()
      ]
    }
})

处理完后vue.config.js整体代码如下

复制代码
const { defineConfig } = require("@vue/cli-service");
const NodePolyfillPlugin = require("node-polyfill-webpack-plugin")

module.exports = defineConfig({
  transpileDependencies: true,
  lintOnSave: false,
  devServer: {
    port: 8080, 
    host: '0.0.0.0',
    client: {
      webSocketURL: 'ws://0.0.0.0:8080/ws',
    },
    headers: {
      'Access-Control-Allow-Origin': '*',
    },
    proxy: {
      '/':{
        ws: false,
        target:"http://127.0.0.1:3000",
        pathRewrite:{
          "^/":"/"
        }
      }
    }
  },
  configureWebpack: {
      plugins: [
          new NodePolyfillPlugin()
        ],
    externals: {
      './cptable': 'var cptable'
    },
    resolve: {
      fallback: {
        fs: false,
        crypto: false,
      }
    },
  }

});
相关推荐
小白变怪兽1 小时前
一、react18+项目初始化(vite)
前端·react.js
ai小鬼头1 小时前
AIStarter如何快速部署Stable Diffusion?**新手也能轻松上手的AI绘图
前端·后端·github
墨菲安全2 小时前
NPM组件 betsson 等窃取主机敏感信息
前端·npm·node.js·软件供应链安全·主机信息窃取·npm组件投毒
GISer_Jing2 小时前
Monorepo+Pnpm+Turborepo
前端·javascript·ecmascript
天涯学馆2 小时前
前端开发也能用 WebAssembly?这些场景超实用!
前端·javascript·面试
我在北京coding3 小时前
TypeError: Cannot read properties of undefined (reading ‘queryComponents‘)
前端·javascript·vue.js
前端开发与ui设计的老司机4 小时前
UI前端与数字孪生结合实践探索:智慧物流的货物追踪与配送优化
前端·ui
全能打工人4 小时前
前端查询条件加密传输方案(SM2加解密)
前端·sm2前端加密
海天胜景4 小时前
vue3 获取选中的el-table行数据
javascript·vue.js·elementui