Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

xlsx + electron: jszip reference error #2177

Closed
aplr opened this issue Nov 18, 2020 · 3 comments
Closed

xlsx + electron: jszip reference error #2177

aplr opened this issue Nov 18, 2020 · 3 comments

Comments

@aplr
Copy link

aplr commented Nov 18, 2020

Hi, I've created a plain electron app using electron-forge and its typescript & webpack template. When calling XLSX.read in the renderer.ts, the following error is thrown, leading to this line in jszip.js. Package versions can be seen in the package.json below.

ReferenceError
Uncaught ReferenceError: require is not defined
    at e (jszip.js:26)
    at jszip.js:26
    at jszip.js:1
    at Object../node_modules/xlsx/jszip.js (jszip.js:1)
    at __webpack_require__ (bootstrap:789)
    at fn (bootstrap:100)
    at make_xlsx_lib (xlsx.js:2960)
    at Object../node_modules/xlsx/xlsx.js (xlsx.js:21698)
    at __webpack_require__ (bootstrap:789)
    at fn (bootstrap:100)
package.json
{
  "devDependencies": {
    "@electron-forge/cli": "^6.0.0-beta.54",
    "@electron-forge/maker-deb": "^6.0.0-beta.54",
    "@electron-forge/maker-rpm": "^6.0.0-beta.54",
    "@electron-forge/maker-squirrel": "^6.0.0-beta.54",
    "@electron-forge/maker-zip": "^6.0.0-beta.54",
    "@electron-forge/plugin-webpack": "^6.0.0-beta.54",
    "@marshallofsound/webpack-asset-relocator-loader": "^0.5.0",
    "@typescript-eslint/eslint-plugin": "^4.8.1",
    "@typescript-eslint/parser": "^4.8.1",
    "css-loader": "^4.3.0",
    "electron": "11.0.1",
    "eslint": "^7.13.0",
    "eslint-plugin-import": "^2.22.1",
    "fork-ts-checker-webpack-plugin": "^5.2.1",
    "node-loader": "^1.0.2",
    "style-loader": "^1.3.0",
    "ts-loader": "^8.0.11",
    "typescript": "^4.0.5"
  },
  "dependencies": {
    "electron-squirrel-startup": "^1.0.0",
    "xlsx": "^0.16.8"
  }
}

Did anyone of you already encounter this issue, I guess that's a quite standard setup with webpack & typescript.
Do you have any Idea what's going on here and how to fix that, any help is appreciated!

@simplecommerce
Copy link

simplecommerce commented Jan 26, 2021

@aplr Hi, did you manage to get this error fixed?

I am encountering the same thing but with Parcel Builder.

Update

I am using parcel 2, and I had to do this to remove the error: --no-scope-hoist.

Building with this option made it work.

@Komodood
Copy link

@aplr I have the same error, I try to start reading xlsx.ReadFile/read or via fs in the react function , but it gives the same error. Were you able to solve the problem?

@SheetJSDev
Copy link
Contributor

@aplr for electron, the node module should be required even in the renderer thread. The electron demo does this Related: #2209

@simplecommerce please raise a new issue with more details (like a small project so we can reproduce the issue).

@Komodood readFile cannot be used in a browser context since it uses th e nodejs fs module under the hood. Please raise a new issue with more details so we can reproduce.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants