Closed VaskaDagamas closed 6 years ago
the following help me https://github.com/protobi/js-xlsx/issues/78#issuecomment-315063340
and add next config
module.exports = {
// (...)
plugins: [
// (...)
new webpack.IgnorePlugin(/cptable/)
],
node: {
fs: "empty"
},
externals: [
{ "./cptable": "var cptable", "./jszip": "jszip" }
]
};
Webpack 5 workaround:
use strict
cause runtime syntax error
function (e) {
"use strict";
e.exports = jszip;
}
// webpack
module.exports = {
plugins: [
new webpack.IgnorePlugin({ resourceRegExp: /cptable/ })
],
resolve: {
fallback: {
fs: false,
crypto: require.resolve('crypto-browserify'),
stream: require.resolve('stream-browserify')
}
},
externals: [
{ './cptable': 'var cptable' }
]
}
add global variable https://github.com/protobi/js-xlsx/blob/v0.8.6/xlsx.js#L1335
// xlsxWithStyle.js
import jszip from 'xlsx-style/dist/jszip'
if (global.window) {
window.JSZip = jszip
} else {
global.JSZip = jszip
}
const xlsxWithStyle = (async () => {
const { default: xlsxStyle } = await import('xlsx-style')
return xlsxStyle
})()
export default xlsxWithStyle
usage
import xlsxWithStyle from './xlsxWithStyle'
const asyncPkg = await xlsxWithStyle
const AsyncXlsxWithStyle = await asyncPkg
AsyncXlsxWithStyle.write()
Used webpack try import like
import XLSX from 'xlsx-style' import * as FileSaver from 'file-saver';
orimport * as XLXS from "xlsx-style" import * as FileSaver from 'file-saver';
but have next errors when compilewhen import