skellock / typescript-with-electron-react-kit

Don't just start your Electron app... TWERKit.
https://skellock.github.io/typescript-with-electron-react-kit
MIT License
145 stars 23 forks source link

Unexpected token import #106

Open CzBuCHi opened 6 years ago

CzBuCHi commented 6 years ago

when calling npm test i got this error:

 FAIL  test\storyshots.test.ts
  ● Test suite failed to run

    C:\projects\easy-runner\node_modules\lodash-es\flattenDeep.js:1
    ({"Object.<anonymous>":function(module,exports,require,__dirname,__filename,global,jest){import baseFlatten from './_baseFlatten.js';
                                                                                             ^^^^^^

    SyntaxError: Unexpected token import

      at ScriptTransformer._transformAndBuildScript (node_modules/jest-runtime/build/script_transformer.js:305:17)
      at Object.<anonymous> (node_modules/@storybook/react/dist/client/preview/element_check.js:16:20)
      at Object.<anonymous> (node_modules/@storybook/react/dist/client/preview/render.js:31:22)

any idea why is this happening?

PS: also got test fail for "loads from electron" in "src\main\main-window\load-url.test.ts" but that can be fixed by using posix version of path.join

PS>check-node-version --print
node: 9.3.0
npm: 5.6.0
yarn: 1.3.2

PS> systeminfo | findstr /C:"OS"
OS Name:                   Microsoft Windows 10 Home
OS Version:                10.0.15063 N/A Build 15063
OS Manufacturer:           Microsoft Corporation
OS Configuration:          Standalone Workstation
OS Build Type:             Multiprocessor Free
BIOS Version:              American Megatrends Inc. 1708, 10.04.2013
skellock commented 6 years ago

Hey, thanks for the issue!

I haven't run the tests from windows yet. There's probably a few places where switching from hardcoded slash paths to path.resolve() will fix up things.

That lodash-es import, was that something specific to your project?

The import statement that it's bombing on is because import isn't a thing on node.js yet. I wonder if switching to a non-es version of lodash would help?

skellock commented 6 years ago

Also, https://github.com/standard-things/esm might be able to help as it polyfills import into node.js.

CzBuCHi commented 6 years ago

about path: simplest would be to use path.posix. instead of path. - it forces path with slashes even on windows

about lodash-es: im getting this error on your code (only git clone', 'npm install' and 'npm test where called) ... switch to non-es lodash can do, because im not who is importing this (lodash is not in package.json) ... now reading about esm .... later