简体   繁体   中英

"SyntaxError: Invalid regular expression flags" in React/Electron

I have a React/Electron app that I'm building on & for Windows with electron-builder . It builds fine, but when I try to run the packaged program I get

Uncaught Exception:
C:\My Project\dist\win-unpacked\resources\app.asar\build\electron.js:1
(function (exports, require, module, __filename, __dirname, process, global, Buffer) { return function (exports, require, module, __filename, __dirname) { /home/jd/projects/app/src/start.js
                                                                                                                                                           ^

SyntaxError: Invalid regular expression flags
    at new Script (vm.js:79:7)
    at createScript (vm.js:251:10)
    at Object.runInThisContext (vm.js:303:10)
    at Module._compile (internal/modules/cjs/loader.js:660:28)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:704:10)
    at Module.load (internal/modules/cjs/loader.js:602:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:541:12)
    at Function.Module._load (internal/modules/cjs/loader.js:533:3)
    at Object.<anonymous> (C:\My Project\dist\win-unpacked\resources\electron.asar\browser\init.js:188:8)
    at Object.<anonymous> (C:\My Project\dist\win-unpacked\resources\electron.asar\browser\init.js:190:3)

I'm trying to make sense of this. I've unpacked electron.asar to look at init.js , which has 189 lines (?) and line 188 is

Module._load(path.join(packagePath, mainStartupScript), Module, true)

This seems like it's something happening in Electron, outside of the app I've written being called? This looks like an error before it even gets to my main start.js for React.

Appreciate any thoughts on how I can go about debugging this, please let me know if there's any more useful information I can include.

EDIT : Of course I should have mentioned, I don't use any regex anywhere in my app.

EDIT 2 : I've uploaded my package.json to this gist

EDIT 3 : This project was bootstrapped with create-react-app

According to the error message, there is text that is interpreted as a regular expression.

Looking at the error message you pasted, you can see that the file C:\\My Project\\dist\\win-unpacked\\resources\\app.asar\\build\\electron.js starts correctly and they contains the string /home/jd/projects/app/src/start.js .

I think that /home/jd is parsed as a regular expression with the flags jd , although the only valid flags are gimuy ( source ).

My advice would be that you clean your build directory C:\\My Project\\dist\\win-unpacked\\resources\\app.asar\\build\\ and try to compile again, although I have no idea how the string /home/jd/projects/app/src/start.js appeared in your built asset. Hope it helps!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM