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

});
相关推荐
XinZong11 小时前
实测OpenClaw虾淘:全民工具AI时代,冷门非工具类的Skill还能出圈吗?
javascript
kjs--11 小时前
浏览器书签执行脚本
前端
烛衔溟11 小时前
TypeScript 类的类型 —— 作为类型使用
javascript·ubuntu·typescript
之歆11 小时前
Day16_JavaScript 轮播图与事件工程实战(下篇)
服务器·开发语言·前端·javascript·网络·性能优化
沄媪11 小时前
CSRF 跨站请求伪造
前端·ctf·csrf
kyriewen12 小时前
我关掉了Copilot:因为我写的代码出现在了别人的建议里
前端·javascript·ai编程
欧雷殿12 小时前
从「吸引子引导工程」看我的「一人公司」实践
前端·人工智能·后端
SmartRadio12 小时前
STM32WLE5 LoRa Smart TDMA 完整协议栈实现(工程级可直接编译)-【1】
javascript·stm32·单片机·嵌入式硬件·lora·自组网·smart tdma
wordbaby12 小时前
React Native + RNOH:一个 `lazyScreen()` 搞定 48 页面启动懒加载
前端·react native