wavesoft / local-echo

A local-echo controller for xterm.js
Apache License 2.0
142 stars 71 forks source link

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

Open fisyher opened 4 years ago

fisyher commented 4 years ago

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 commented 4 years ago

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