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,
      }
    },
  }

});
相关推荐
daols886 小时前
vue vxe-table 自适应列宽,根据内容自适应宽度的2种使用方式
vue.js·vxe-table
小小小小宇7 小时前
虚拟列表兼容老DOM操作
前端
悦悦子a啊7 小时前
Python之--基本知识
开发语言·前端·python
安全系统学习7 小时前
系统安全之大模型案例分析
前端·安全·web安全·网络安全·xss
涛哥码咖8 小时前
chrome安装AXURE插件后无效
前端·chrome·axure
OEC小胖胖8 小时前
告别 undefined is not a function:TypeScript 前端开发优势与实践指南
前端·javascript·typescript·web
行云&流水8 小时前
Vue3 Lifecycle Hooks
前端·javascript·vue.js
Sally璐璐8 小时前
零基础学HTML和CSS:网页设计入门
前端·css
老虎06279 小时前
JavaWeb(苍穹外卖)--学习笔记04(前端:HTML,CSS,JavaScript)
前端·javascript·css·笔记·学习·html
三水气象台9 小时前
用户中心Vue3网页开发(1.0版)
javascript·css·vue.js·typescript·前端框架·html·anti-design-vue