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

ERROR in native_modules/node-gyp1.js from Terser plugin 'return' outside of function #468

Closed
clementlize opened this issue Jan 22, 2022 · 5 comments

Comments

@clementlize
Copy link

Bug report

I am trying to make an app using electron-forge and I have an error from terser-webpack-plugin. I can start my app but I can't run a make. My project is based on this template, based itself on the electron-forge Webpack+Typescript template

Actual Behavior

$ electron-forge package --platform linux
✔ Checking your system
✖ Compiling Main Process Code

An unhandled error has occurred inside Forge:
Compilation errors in the main process: assets by status 9.41 MiB [cached] 7 assets
1712 modules

ERROR in native_modules/node-gyp1.js
native_modules/node-gyp1.js from Terser plugin
'return' outside of function [native_modules/node-gyp1.js:45,2]
    at js_error (/mnt/datadev/perso/myapp/node_modules/terser-webpack-plugin/node_modules/terser/dist/bundle.min.js:550:11)
    at croak (/mnt/datadev/perso/myapp/node_modules/terser-webpack-plugin/node_modules/terser/dist/bundle.min.js:1274:9)
    at statement (/mnt/datadev/perso/myapp/node_modules/terser-webpack-plugin/node_modules/terser/dist/bundle.min.js:1477:21)
    at _embed_tokens_wrapper (/mnt/datadev/perso/myapp/node_modules/terser-webpack-plugin/node_modules/terser/dist/bundle.min.js:1339:26)
    at block_ (/mnt/datadev/perso/myapp/node_modules/terser-webpack-plugin/node_modules/terser/dist/bundle.min.js:2172:20)
    at statement (/mnt/datadev/perso/myapp/node_modules/terser-webpack-plugin/node_modules/terser/dist/bundle.min.js:1403:29)
    at _embed_tokens_wrapper (/mnt/datadev/perso/myapp/node_modules/terser-webpack-plugin/node_modules/terser/dist/bundle.min.js:1339:26)
    at if_ (/mnt/datadev/perso/myapp/node_modules/terser-webpack-plugin/node_modules/terser/dist/bundle.min.js:2155:44)
    at statement (/mnt/datadev/perso/myapp/node_modules/terser-webpack-plugin/node_modules/terser/dist/bundle.min.js:1473:24)
    at _embed_tokens_wrapper (/mnt/datadev/perso/myapp/node_modules/terser-webpack-plugin/node_modules/terser/dist/bundle.min.js:1339:26)

webpack 5.39.1 compiled with 1 error in 18683 ms
    at cb (/mnt/datadev/perso/myapp/node_modules/@electron-forge/plugin-webpack/src/WebpackPlugin.ts:252:31)
    at finalCallback (/mnt/datadev/perso/myapp/node_modules/webpack/lib/Compiler.js:415:32)
    at /mnt/datadev/perso/myapp/node_modules/webpack/lib/Compiler.js:432:13
    at Hook.eval [as callAsync] (eval at create (/mnt/datadev/perso/myapp/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:6:1)
    at Hook.CALL_ASYNC_DELEGATE [as _callAsync] (/mnt/datadev/perso/myapp/node_modules/tapable/lib/Hook.js:18:14)
    at onCompiled (/mnt/datadev/perso/myapp/node_modules/webpack/lib/Compiler.js:430:21)
    at /mnt/datadev/perso/myapp/node_modules/webpack/lib/Compiler.js:1106:17
    at Hook.eval [as callAsync] (eval at create (/mnt/datadev/perso/myapp/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:6:1)
    at Hook.CALL_ASYNC_DELEGATE [as _callAsync] (/mnt/datadev/perso/myapp/node_modules/tapable/lib/Hook.js:18:14)
    at /mnt/datadev/perso/myapp/node_modules/webpack/lib/Compiler.js:1102:33
    at finalCallback (/mnt/datadev/perso/myapp/node_modules/webpack/lib/Compilation.js:2249:11)
    at /mnt/datadev/perso/myapp/node_modules/webpack/lib/Compilation.js:2540:11
    at Hook.eval [as callAsync] (eval at create (/mnt/datadev/perso/myapp/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:6:1)
    at Hook.CALL_ASYNC_DELEGATE [as _callAsync] (/mnt/datadev/perso/myapp/node_modules/tapable/lib/Hook.js:18:14)
    at /mnt/datadev/perso/myapp/node_modules/webpack/lib/Compilation.js:2533:38
    at eval (eval at create (/mnt/datadev/perso/myapp/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:17:1)
error Command failed with exit code 1.

Here is my package.json dependencies:

"dependencies": {
    "@babel/core": "^7.16.10",
    "@babel/plugin-transform-runtime": "^7.16.10",
    "@babel/preset-env": "^7.16.11",
    "@babel/preset-react": "^7.16.7",
    "@babel/preset-typescript": "^7.16.7",
    "@babel/runtime": "^7.16.7",
    "@emotion/react": "^11.7.1",
    "@emotion/styled": "^11.6.0",
    "@fontsource/roboto": "^4.5.1",
    "@journeyapps/sqlcipher": "^5.3.1",
    "@mui/material": "^5.2.8",
    "ajv": "^8.9.0",
    "aws-sdk": "^2.1062.0",
    "dotenv": "^14.2.0",
    "electron-is-dev": "^2.0.0",
    "electron-store": "^8.0.1",
    "jsonfile": "^6.1.0",
    "mock-aws-s3": "^4.0.2",
    "nock": "^13.2.2",
    "postcss-loader": "^6.2.1",
    "react": "17.0.2",
    "react-dom": "17.0.2",
    "react-hot-loader": "4.13.0",
    "sqlite3": "^5.0.2"
  },
  "devDependencies": {
    "@electron-forge/cli": "6.0.0-beta.57",
    "@electron-forge/maker-deb": "6.0.0-beta.57",
    "@electron-forge/maker-rpm": "6.0.0-beta.57",
    "@electron-forge/maker-squirrel": "6.0.0-beta.57",
    "@electron-forge/maker-zip": "6.0.0-beta.57",
    "@electron-forge/plugin-webpack": "6.0.0-beta.57",
    "@marshallofsound/webpack-asset-relocator-loader": "0.5.0",
    "@testing-library/jest-dom": "5.14.1",
    "@testing-library/react": "11.2.7",
    "@types/electron-devtools-installer": "2.2.0",
    "@types/jest": "26.0.23",
    "@types/react": "17.0.11",
    "@types/react-dom": "17.0.8",
    "@types/react-redux": "^7.1.22",
    "@types/sqlite3": "^3.1.8",
    "@typescript-eslint/eslint-plugin": "4.27.0",
    "@typescript-eslint/parser": "4.27.0",
    "@vercel/webpack-asset-relocator-loader": "^1.7.0",
    "ajv-formats": "^2.1.1",
    "babel-loader": "8.2.2",
    "cross-env": "7.0.3",
    "css-loader": "^6.5.1",
    "electron": "13.1.2",
    "electron-rebuild": "^3.2.7",
    "eslint": "7.29.0",
    "eslint-config-prettier": "8.3.0",
    "eslint-config-standard": "16.0.3",
    "eslint-plugin-import": "2.23.4",
    "eslint-plugin-node": "11.1.0",
    "eslint-plugin-prettier": "3.4.0",
    "eslint-plugin-promise": "5.1.0",
    "eslint-plugin-react": "7.24.0",
    "eslint-plugin-standard": "5.0.0",
    "file-loader": "^6.2.0",
    "jest": "27.0.4",
    "npm-run-all": "4.1.5",
    "prettier": "2.3.1",
    "sass": "^1.48.0",
    "sass-loader": "^12.4.0",
    "style-loader": "^3.3.1",
    "ts-jest": "27.0.3",
    "typescript": "4.3.4",
    "wait-on": "5.3.0"
  },

Expected Behavior

The make process should complete, I'm sorry I don't know much about terser-webpack-plugin in particular.

How Do We Reproduce?

This is the tricky part. I made a new project using the electron-forge Webpack+Typescript template and added the native modules (sqlite3, @journeyapps/sqlcipher) and everything works perfectly.

I am currently unable to reproduce this outside of my working project. If you have time to investigate, here is the project, the branch to clone is wip_distribute2.

Please paste the results of npx webpack-cli info here, and mention other relevant information

System:
    OS: Linux 5.13 Ubuntu 20.04.3 LTS (Focal Fossa)
    CPU: (4) x64 Intel(R) Core(TM) i5-6600 CPU @ 3.30GHz
    Memory: 1.10 GB / 15.54 GB
  Binaries:
    Node: 16.13.2 - ~/.nvm/versions/node/v16.13.2/bin/node
    Yarn: 1.22.17 - ~/.nvm/versions/node/v16.13.2/bin/yarn
    npm: 8.1.2 - ~/.nvm/versions/node/v16.13.2/bin/npm
  Browsers:
    Chrome: 97.0.4692.71
    Firefox: 96.0
  Packages:
    babel-loader: 8.2.2 => 8.2.2 
    css-loader: ^6.5.1 => 6.5.1 
    file-loader: ^6.2.0 => 6.2.0 
    postcss-loader: ^6.2.1 => 6.2.1 
    react-hot-loader: 4.13.0 => 4.13.0 
    sass-loader: ^12.4.0 => 12.4.0 
    style-loader: ^3.3.1 => 3.3.1

I obviously took a close look at the issue #281 but nothing mentioned here works. The issue is also pretty old and concerned old versions.

The version requested by my dependencies is 5.1.1 ; I tried to pin 5.3.0 but the same error occurs.
I also tried to pin terser version, without success.

@alexander-akait
Copy link
Member

Can you provide code of node-gyp1.js?

@clementlize
Copy link
Author

Can you provide code of node-gyp1.js?

I spent nearly an hour looking for this file, but I couldn't find it. Not in the node_modules, not in the out folder, I don't understand where it can be.

Do you know where it might be?

@alexander-akait
Copy link
Member

Sorry no, I don't know your application and configuration, but based on an error message, you have invalid JS, i.e. global return

@clementlize
Copy link
Author

Ok thank you for your help. I ended up building again my project from scratch, I don't have any clue how this happened.

@bakabird
Copy link

For guys who come later, you can use this to handle it 。

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

3 participants