运行 npm install 时,我正在使用react-boilerplate我看到这些错误
Building the Webpack DLL...
Hash: 7f68501fbcd6b8f05530
Version: webpack 4.12.0
Time: 3566ms
Built at: 08/05/2018 6:10:17 PM
Asset Size Chunks Chunk Names
reactBoilerplateDeps.dll.js 4.81 MiB reactBoilerplateDeps [emitted] [big] reactBoilerplateDeps
chunk {reactBoilerplateDeps} reactBoilerplateDeps.dll.js (reactBoilerplateDeps) 4.15 MiB [entry] [rendered]
WARNING in ./node_modules/xlsx-style/ods.js
Module not found: Error: Can't resolve '../xlsx' in '/Users/mehrnooshhajkhalil/react-boilerplate/node_modules/xlsx-style'
@ ./node_modules/xlsx-style/ods.js
@ ./node_modules/xlsx-style/xlsx.js
@ ./node_modules/node-excel-export/lib/excel.js
@ ./node_modules/node-excel-export/index.js
@ dll reactBoilerplateDeps
ERROR in ./node_modules/xlsx-style/dist/cpexcel.js
Module not found: Error: Can't resolve './cptable' in '/Users/mehrnooshhajkhalil/react-boilerplate/node_modules/xlsx-style/dist'
@ ./node_modules/xlsx-style/dist/cpexcel.js 807:16-41
@ ./node_modules/xlsx-style/xlsx.js
@ ./node_modules/node-excel-export/lib/excel.js
@ ./node_modules/node-excel-export/index.js
@ dll reactBoilerplateDeps
ERROR in ./node_modules/xlsx-style/xlsx.js
Module not found: Error: Can't resolve 'fs' in '/Users/mehrnooshhajkhalil/react-boilerplate/node_modules/xlsx-style'
@ ./node_modules/xlsx-style/xlsx.js 1204:27-40 1340:8-24
@ ./node_modules/node-excel-export/lib/excel.js
@ ./node_modules/node-excel-export/index.js
@ dll reactBoilerplateDeps
ERROR in ./node_modules/xlsx-style/ods.js
Module not found: Error: Can't resolve 'fs' in '/Users/mehrnooshhajkhalil/react-boilerplate/node_modules/xlsx-style'
@ ./node_modules/xlsx-style/ods.js 58:8-24
@ ./node_modules/xlsx-style/xlsx.js
@ ./node_modules/node-excel-export/lib/excel.js
@ ./node_modules/node-excel-export/index.js
@ dll reactBoilerplateDeps
ERROR in ./node_modules/xlsx-style/ods.js
Module not found: Error: Can't resolve 'xlsx' in '/Users/mehrnooshhajkhalil/react-boilerplate/node_modules/xlsx-style'
@ ./node_modules/xlsx-style/ods.js 13:21-41
@ ./node_modules/xlsx-style/xlsx.js
@ ./node_modules/node-excel-export/lib/excel.js
@ ./node_modules/node-excel-export/index.js
@ dll reactBoilerplateDeps
removed 1 package and audited 53190 packages in 30.134s
我也尝试过
rm -rf节点模块 npm清理缓存--force npm install
但是他们都没有解决我的问题
节点版本:v10.8.0 npm版本:6.2.0
答案 0 :(得分:1)
我已经阅读了大量相关主题并尝试了所有内容。但就我而言,这有助于:
在externals
的Webpack配置中,将{ "../xlsx.js": "var _XLSX" }
替换为{ "../xlsx": "var _XLSX" }
答案 1 :(得分:0)
我在这个问题上停留了大约1周,问题是,当您想使用任何使用export excel的软件包时,他们使用fs表示文件系统的缩写。浏览器没有任何浏览器。
因此,几乎不可能从前端的reactboilerplate导出excel文件,我确实通过使用node-excel-export来处理它,然后为此编写了一个API:
export const exportIssues = (req, res) => {
const styles = {
headerDark: {
fill: {
fgColor: {
rgb: 'FF000000'
}
},
font: {
color: {
rgb: 'FFFFFFFF'
},
sz: 14,
bold: true,
underline: true
}
}
};
//Here you specify the export structure
const issueSpecification = {
HousingManager: { // <- the key should match the actual data key
displayName: 'Housing manager', // <- Here you specify the column header
headerStyle: styles.headerDark, // <- Header style
width: 120 // <- width in pixels
},
CompanyName: { // <- the key should match the actual data key
displayName: 'Company name', // <- Here you specify the column header
headerStyle: styles.headerDark, // <- Header style
width: 120 // <- width in pixels
},
HousingManagerEmail: { // <- the key should match the actual data key
displayName: 'Housing manager email', // <- Here you specify the column header
headerStyle: styles.headerDark, // <- Header style
width: 120 // <- width in pixels
}
}
const issueData = [
{HousingManager:'sss', CompanyName: 'xxx' , HousingManagerEmail:'xx@x.com'},
{HousingManager:'sss', CompanyName: 'xxx' , HousingManagerEmail:'xx@x.com'},
]
const report = excel.buildExport(
[ // <- Notice that this is an array. Pass multiple sheets to create multi sheet report
{
name: 'Issues', // <- Specify sheet name (optional)
specification: issueSpecification, // <- Report specification
data: issueData // <-- Report data
}
]
);
// You can then return this straight
res.set("Content-Disposition", "attachment;filename=report.xlsx");
res.set("Content-type", "application/vnd.ms-excel")
res.attachment('report.xlsx'); // This is sails.js specific (in general you need to set headers)
return res.send(report);
};
然后在前端调用此函数:
exportIssues = (e) =>{
axios.get('APIURL',{
responseType: 'blob',
})
.then((response) => {
download(response.data, "Issues.xlsx", "application/vnd.ms-excel");
})
};
答案 2 :(得分:0)
我找到了解决方法。
请在ods.js中替换以下代码
if(typeof XLSX !== 'undefined') return XLSX.utils;
if(typeof module !== "undefined" && typeof require !== 'undefined')
{
try
{
return require('./' + 'xlsx').utils;
}
catch(e)
{
try
{
return require('./' + 'xlsx').utils;
}
catch(ee)
{
return require('./xlsx').utils;
}
}
throw new Error("Cannot find XLSX utils");
};
答案 3 :(得分:0)
我使用yarn add xlsx --save
下载了xlsx模块,它解决了该问题。