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

});
相关推荐
汉堡大王952713 分钟前
# AI 终于能"干活"了——Function Calling 完全指南
javascript·人工智能·机器学习
明君8799714 分钟前
说说我为什么放弃使用 GetX,转而使用 flutter_bloc + GetIt
前端·flutter
Jingyou17 分钟前
用 Astro 搭建个人博客:从零到上线的完整实践
前端
吴声子夜歌21 分钟前
JavaScript——call()、apply()和bind()
开发语言·前端·javascript
小哈猪23 分钟前
CSS Flex 与 Grid:谁才是布局之王?
javascript
高桥凉介发量惊人26 分钟前
质量与交付篇(2/6):CI/CD 实战——自动构建、签名、分发
前端
leafyyuki28 分钟前
SSE 同域长连接排队问题解析与前端最佳实践
前端·javascript·人工智能
高桥凉介发量惊人29 分钟前
质量与交付篇(3/6):崩溃分析与线上问题回溯机制
前端
angerdream30 分钟前
最新版vue3+TypeScript开发入门到实战教程之路由详解三
前端·javascript·vue.js
好雨知时节t31 分钟前
sleep 函数在React项目中的运用
javascript