question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Parsing error: 'import' and 'export' may appear only with 'sourceType: module'

See original GitHub issue

This seems like a really cool eslint config! I gave it a try on a typescript project with eslint config

{
  "extends": ["hardcore", "hardcore/fp", "hardcore/node"],
  "overrides": [
    {
      "files": ["*.js"],
      "extends": ["hardcore/ts-for-js"],
      "parserOptions": { "project": "./tsconfig.json" }
    }
  ]
}

and get the error

/home/pong/utils/src/cookies/cookies.ts
  3:1  error  Parsing error: 'import' and 'export' may appear only with 'sourceType: module'

I tried with a ts config of {} as suggested in readme.

I am using E6 syntax and want to use the import/export syntax. Do you know what has gone wrong here?

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:8 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
EvgenyOrekhovcommented, Oct 29, 2020

In which cases would you want to use eslint-typscript for regular javascript?

  • when you use new ES features, like class properties or optional chaining, and want to run additional checks on those
  • when you want to run additional type-aware checks

Here are some useful typescript-eslint rules that work with JavaScript (they all are included in hardcore/ts-for-js):


No files matching the pattern "/home/pong//utils" were found.

Looks like you are facing a known issue with eslint-plugin-import and its import/no-unused-modules rule, see https://github.com/benmosher/eslint-plugin-import/issues/1645. I guess you should just disable this rule.

Let me know if that helps.

1reaction
EvgenyOrekhovcommented, Oct 28, 2020

BTW, I can see that Node.js 14 was promoted to LTS two days ago, which means now we should be able to use ES6 modules both on client side and on server side. I guess I should set "sourceType": "module" as default in eslint-config-hardcore then. And also discourage the use of commonjs. Created https://github.com/EvgenyOrekhov/eslint-config-hardcore/issues/164.

Read more comments on GitHub >

github_iconTop Results From Across the Web

'import' and 'export' may appear only with 'sourceType: module ...
I get this error since the most recent update. is it possible there this is missing somewhere in the package?
Read more >
ignore eslint error: 'import' and 'export' may only appear at the ...
my solution incase other dont work "parserOptions": { "ecmaVersion": 6, "sourceType" ...
Read more >
'import' and 'export' may appear only with 'sourceType: module ...
Parsing error on .vue files during typescript analysis with javascript sensor - 'import' and 'export' may appear only with 'sourceType: ...
Read more >
ESLint - HackingNote
Ignore Warning: Parsing error: 'import' and 'export' may only appear at the top level. Use babel-eslint as parser and allow import/export ...
Read more >
Solved: Bundle Error: 'import' and 'export' may appear onl...
Bundle Error: 'import' and 'export' may appear only with 'sourceType: ... But I meet an error after I install an es6 modules( @antv/x6...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found