SyntaxError: Unexpected token `export`
See original GitHub issueNode 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:
- Created 4 years ago
- Reactions:4
- Comments:26 (16 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
So, here’s what I did. Cloned your project and ran
npm run build
to get thedist
folder. Created a typeScript project and imported theindex.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 requiresSure @kutyel 😬