SyntaxError: Unexpected token 'export'
See original GitHub issueDescribe the bug
I get the following error when trying to import the package like so import { downloadZip } from "client-zip";
:
SyntaxError: Unexpected token 'export'
at compileFunction (<anonymous>)
at Object.compileFunction (node:vm:352:18)
at wrapSafe (node:internal/modules/cjs/loader:1031:15)
at Module._compile (node:internal/modules/cjs/loader:1065:27)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
at Module.load (node:internal/modules/cjs/loader:981:32)
at Function.Module._load (node:internal/modules/cjs/loader:822:12)
at Module.require (node:internal/modules/cjs/loader:1005:19)
at require (node:internal/modules/cjs/helpers:94:18)
at Object.client-zip (/Users/ericamshukov/Projects/dt_bridge_pipetrekker_spa/.next/server/pages/index.js:20570:18) {
page: '/'
}
To Reproduce Steps to reproduce the behavior:
- Import in TypeScript file
- npm run
SyntaxError: Unexpected token 'export'
Additional context I am developing a project in NextJS and TypeScript, but everything else is working properly.
Issue Analytics
- State:
- Created 2 years ago
- Comments:10 (7 by maintainers)
Top Results From Across the Web
Getting Unexpected Token Export - javascript
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 >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 >How to fix SyntaxError: Unexpected token 'export' in ...
In this article, we are going to see How to fix SyntaxError: Unexpected token 'export' in JavaScript? and what are Es6 modules.
Read more >How to Solve Unexpected Token 'export' Error in JavaScript
To solve the "Uncaught SyntaxError Unexpected token 'export'" error, set the type property to module in your package.json file.
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
@Touffy I was helping a friend debug something similar
Unfortunately with nextjs the solution isn’t simple. There are two things that can be done in nextjs to use this:
You can use a nextjs dynamic component which is only rendered client side:
Then, in that component, you can use a dynamic import to avoid it being included on the server. For example in a callback, you could do the following:
The faster alternative in Node is to call a (fast) native Zip program. I am not an expert on those, and I’m sure there are already performance reviews you can find elsewhere. I don’t mean to be rude, I just don’t want to give you poor advice from a lack of research, and I don’t see why I should do the research. Zipping on the server-side is off-topic for this project. It happens to work in Deno, yes, but that wasn’t even intended.
However, there is a general explanation I can give you. Native programs can use CPU features that are not available to client-zip (because they’re not in JavaScript or WebAssembly), such as a hardware CRC32 primitive, and 256-bit vector operations. Also, Node and native programs have efficient random access to the local filesystem, which means they don’t have to use streaming mode if zipping from there, and they can copy data from one part of the filesystem to another with efficient kernel calls instead of moving it through userspace buffers. As you can see on my benchmark, the native Zip program I used is much faster than client-zip and other JavaScript alternatives. However, I can’t say if it’s the fastest, or the best suited for integration with Node.