gpt4 book ai didi

node.js - 在 nextJS (next.config.js) 中设置 webpack 配置

转载 作者:行者123 更新时间:2023-12-05 06:57:05 25 4
gpt4 key购买 nike

我正在使用 NextJS 并使用 react-data-export生成xls文件的插件。在描述中它说:

This library uses file-saver and xlsx and usingjson-loader will do the magic for you.

///webpack.config.js
vendor: [
.....
'xlsx',
'file-saver'
],
.....
node: {fs: 'empty'},
externals: [
{'./cptable': 'var cptable'},
{'./jszip': 'jszip'}
]

但我不知道如何实现它并得到这样的错误:

The static directory has been deprecated in favor of the public directory. https://err.sh/vercel/next.js/static-dir-deprecated
Defining routes from exportPathMap
event - compiled successfully
> Ready on http://localhost:80 or http://localhost
> Ready on https://localhost:443 or https://localhost
event - build page: /menu_accounting/ReportGross
wait - compiling...
error - ./node_modules/react-export-excel/node_modules/xlsx/xlsx.js
Module not found: Can't resolve 'fs' in '/home/ahmadb/repos/lorry-erp/node_modules/react-export-excel/node_modules/xlsx'
Could not find files for /menu_accounting/ReportGross in .next/build-manifest.json

最佳答案

我遇到了同样的问题,我的解决方案是这样的:

  1. 安装这个包(如果你安装了,忽略这个)

npm install file-saver --save

npm install xlsx

npm install --save-dev json-loader

  1. 将此添加到您的nextjs.config.js
    const path = require('path')

module.exports = {
...

//Add this lines
webpack: (config, { isServer }) => {
// Fixes npm packages that depend on `fs` module
if (!isServer) {
config.node = {
fs: 'empty'
}
}

return config
}

}

关于node.js - 在 nextJS (next.config.js) 中设置 webpack 配置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64981478/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com