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

});
相关推荐
IT、木易几秒前
大白话 CSS 中transform属性的常见变换类型(平移、旋转、缩放等)及使用场景
前端·css·面试
1024小神20 分钟前
更改github action工作流的权限
前端·javascript
Epicurus25 分钟前
JavaScript无阻塞加载的方式
前端·javascript
1024小神27 分钟前
tauri程序使用github action发布linux中arm架构
前端·javascript
ahhdfjfdf29 分钟前
最全的`Map` 和 `WeakMap`的区别
前端
LAM LAB33 分钟前
【VBA】WPS/PPT设置标题字体
javascript·powerpoint·vba·wps
JYeontu34 分钟前
实现一个带@功能的输入框组件
前端·javascript·vue.js
一颗奇趣蛋1 小时前
vue-router的query和params的区别(附实际用法)
前端·vue.js
孤城2861 小时前
MAC电脑常用操作
前端·macos·快捷键·新手·电脑使用
木亦Sam1 小时前
Vue DevTools逆向工程:自己实现一个组件热更新调试器
前端