![](/img/trans.png)
[英]TypeError: Cannot set properties of undefined (setting 'styles') + Using withLess/withSass/withCSS in next.config.js NextJS
[英]setup webpack config in nextJS (next.config.js)
我正在使用 NextJS 並使用react-data-export插件生成 xls 文件。 在描述中它說:
該庫使用文件保護程序和xlsx ,使用json-loader將為您帶來魔力。
///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
我有同樣的問題,我的解決方案是這樣的:
npm install file-saver --save
npm 安裝 xlsx
npm install --save-dev json-loader
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
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.