Skip to content
This repository has been archived by the owner on Nov 16, 2023. It is now read-only.

SyntaxError: Unexpected token import #213

Open
samuelrego opened this issue Oct 21, 2018 · 1 comment
Open

SyntaxError: Unexpected token import #213

samuelrego opened this issue Oct 21, 2018 · 1 comment

Comments

@samuelrego
Copy link

I have created one NPM library by using typescript react starter. In tsconfig file i given module as 'esnext' when i build and import it in another project it throwing error while doing npm run test. but it works fine in run and build time.

if put module as 'commonjs' it works fine for me. but i am not able to import images (import logo from './logo.ppng')

Please let me know how to run test cases by setuping module as 'esnext';

console log:

E:\frontend\-ui-component\src\setupTests.ts:7
  import * as enzyme from 'enzyme';
  ^^^^^^

  SyntaxError: Unexpected token import

    at ScriptTransformer._transformAndBuildScript (node_modules/jest-runtime/build/ScriptTransformer.js:289:17)
        at <anonymous>
    at process._tickCallback (internal/process/next_tick.js:189:7)

Test Suites: 2 failed, 2 total
Tests:       0 total
Snapshots:   0 total
Time:        1.907s, estimated 2s
Ran all test suites.

tsconfig of lcomponent (npm pack):

{
  "compilerOptions": {
    "baseUrl": ".",
    "outDir": "build/dist",
    "module": "esnext",
    "target": "es6",
    "lib": ["es6", "dom","es7"],
    "sourceMap": true,
    "allowJs": false,
    "jsx": "react",
    "moduleResolution": "node",
    "rootDir": "src",
    "forceConsistentCasingInFileNames": true,
    "noImplicitReturns": true,
    "noImplicitThis": true,
    "noImplicitAny": true,
    "importHelpers": true,
    "strictNullChecks": true,
    "suppressImplicitAnyIndexErrors": true,
    "noUnusedLocals": true,
    "declaration": true,
  },
  
  "exclude": [
    "node_modules",
    "build",
    "scripts",
    "acceptance-tests",
    "webpack",
    "jest"   
  ]
}

tsconfig of project (where i imported project):

{
  "compilerOptions": {
    "baseUrl": ".",
    "outDir": "build/dist",
    "module": "esnext",
    "target": "es6",
    "lib": ["es2015", "es2017", "dom","esnext","es6"],
    "sourceMap": true,
    "allowJs": false,
    "jsx": "react",
    "moduleResolution": "node",
    "rootDir": "src",
    "forceConsistentCasingInFileNames": true,
    "noImplicitReturns": true,
    "noImplicitThis": true,
    "noImplicitAny": true,
    "importHelpers": true,
    "strictNullChecks": true,
    "suppressImplicitAnyIndexErrors": true,
    "noUnusedLocals": true,
    "declaration": true,
  },
  "exclude": [
    "node_modules",
    "build",
    "scripts",
    "acceptance-tests",
    "webpack",
    "jest",
    "src/setupTests.ts"
  ]
}

@akopchinskiy
Copy link

I have almost the same error: Unexpected token *
In import * as lib from './lib';

module parameters in tsconfig:

"module": "es6",
"target": "es6",
"moduleResolution": "node",

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants