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.

SyntaxError: Unexpected token `export`

See original GitHub issue

Node v10.15.3

Imported like this:

import { List } from 'linqts';

myproject/node_modules/linqts/dist/index.js:10
[0] [1] export { default as List } from './src/list';
[0] [1] ^^^^^^
[0] [1] 
[0] [1] SyntaxError: Unexpected token export
[0] [1]     at new Script (vm.js:80:7)
[0] [1]     at createScript (vm.js:274:10)
[0] [1]     at Object.runInThisContext (vm.js:326:10)
[0] [1]     at Module._compile (internal/modules/cjs/loader.js:664:28)
[0] [1]     at Object.Module._extensions..js (internal/modules/cjs/loader.js:712:10)
[0] [1]     at Module.load (internal/modules/cjs/loader.js:600:32)
[0] [1]     at tryModuleLoad (internal/modules/cjs/loader.js:539:12)
[0] [1]     at Function.Module._load (internal/modules/cjs/loader.js:531:3)
[0] [1]     at Module.require (internal/modules/cjs/loader.js:637:17)
[0] [1]     at require (internal/modules/cjs/helpers.js:22:18)

Here is my tscconfig.json:

{
  "compilerOptions": {
    "declaration": false,
    "noUnusedLocals": true,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "lib": [
      "es2017",
      "dom"
    ],
    "removeComments": false,
    "sourceMap": true,
    "mapRoot": "../dist/",
    "module": "commonjs",
    "moduleResolution": "node",
    "outDir": "../dist/",
    "target": "es2016",
    "allowJs": false,
    "typeRoots": [
      "../node_modules/@types"
    ],
    "baseUrl": "."
    
  }
}

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:4
  • Comments:26 (16 by maintainers)

github_iconTop GitHub Comments

1reaction
mrsauravsahucommented, May 3, 2020

So, here’s what I did. Cloned your project and ran npm run build to get the dist folder. Created a typeScript project and imported the index.js folder from the dist generated. The TS project ran without any errors. The issue is indeed the way you are publishing to npm. I couldn’t find a publish command in your package.json. I can open up a PR, but essentially what we need to do, is to publish the contents of the dist folder, which has all TypeScript imports compiled down to node requires

1reaction
mrsauravsahucommented, Apr 30, 2020

Sure @kutyel 😬

Read more comments on GitHub >

github_iconTop Results From Across the Web

Getting Unexpected Token Export - javascript - Stack Overflow
The problem was that I was changing my code from non-modules to modules and I forgot to delete the imported script file. My...
Read more >
SyntaxError: Unexpected token 'export' in JavaScript
To solve the "Uncaught SyntaxError Unexpected token 'export'" error, set the type property to module in your package.json file.
Read more >
How to fix SyntaxError: Unexpected token 'export' in JavaScript?
In this article, we are going to see How to fix SyntaxError: Unexpected token 'export' in JavaScript? and what are Es6 modules.
Read more >
Unexpected Token Export: A Comprehensive Guide
The “unexpected token export” error occurs because the program's module is incompatible with the program's environment or the user has used the wrong...
Read more >
SyntaxError: Unexpected token 'export' - Abhishek Kumar
In case you are getting error like 'Unexpected token export' while starting the server, then export like below in schema.js
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