How to use zip.js with create-react-app? #258
-
When i load the package using (import * as ZIP from "@zip.js/zip.js") is gives me this error ./node_modules/@zip.js/zip.js/lib/core/codecs/codec-pool-worker.js 85:72
| workerData.worker.addEventListener(MESSAGE_EVENT_TYPE, onMessage, false); i dont know why it happens i tried to read some Q&A in the repository, but i didnt find nothing. Do you guys know the origin of this error? And how to resolve it? |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 12 replies
This comment has been hidden.
This comment has been hidden.
-
To fix this issue, you must include the loader @open-wc/webpack-import-meta-loader in your project. You can do this by using for example react-app-rewired and following these steps:
module.exports = function override(config, env) {
config.module.rules.push({
test: /@zip\.js\/zip\.js\/lib\/core\/codecs\/codec-pool-worker\.js$/,
use: {
loader: require.resolve('@open-wc/webpack-import-meta-loader')
}
});
return config;
}
with:
|
Beta Was this translation helpful? Give feedback.
This comment has been hidden.
This comment has been hidden.
-
You can also use
|
Beta Was this translation helpful? Give feedback.
create-react-app
uses webpack 4 under the hood to build the application and webpack 4 does not fully support web workers without an additional loader.To fix this issue, you must include the loader @open-wc/webpack-import-meta-loader in your project. You can do this by using for example react-app-rewired and following these steps:
npm install react-app-rewired --save-dev
to installreact-app-rewired
npm install @open-wc/webpack-import-meta-loader --save-dev
to install@open-wc/webpack-import-meta-loader
config-overrides.js
in the root folder of your project and paste the following content: