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

"Cannot use import statement outside a module" when using require #20

Open
fisyher opened this issue Apr 20, 2020 · 1 comment
Open

Comments

@fisyher
Copy link

fisyher commented Apr 20, 2020

After installing local-echo as a node module using npm install, I tried to import local-echo using require within an electron app but encountered this error:

var LocalEchoController = require('local-echo')

Exception thrown in developer console:

Uncaught D:\electron-app\node_modules\local-echo\index.js:1
(function (exports, require, module, __filename, __dirname, process, global, Buffer) { return function (exports, require, module, __filename, __dirname) { import LocalEchoController from "./lib/LocalEchoController";
                                                                                                                                                           ^^^^^^

SyntaxError: Cannot use import statement outside a module
    at new Script (vm.js:84:7)
    at createScript (vm.js:258:10)
    at Object.runInThisContext (vm.js:306:10)
    at Module._compile (internal/modules/cjs/loader.js:884:26)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:986:10)
    at Module.load (internal/modules/cjs/loader.js:816:32)
    at Module._load (internal/modules/cjs/loader.js:728:14)
    at Module._load (electron/js2c/asar.js:717:26)
    at Function.Module._load (electron/js2c/asar.js:717:26)
    at Module.require (internal/modules/cjs/loader.js:853:19)

Can you fix this error? Or at least provide a solution on how to fix this error? Thanks

@zhubinsheng
Copy link

Hello, I also encountered a similar problem. Import cannot be used in Es5, and the exception similar to that reported by you cannot be used with require

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

2 participants