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.

/node_modules/upscaler/dist/browser/esm/index.js:1
export { default, } from './upscaler';
^^^^^^

SyntaxError: Unexpected token 'export'

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:10 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
thekevinscottcommented, Dec 9, 2022

I opened https://github.com/hollowshiroyuki/Timi_OCR_Proto/pull/1/files which should resolve the issues you’re seeing (I’m not familiar with TesseractJS, but the script completes without errors).

Some things:


On the subject of needing to load the Node version with require: we bundle the library in a few flavors:

  • ESM (browser only)
  • CJS (node only)
  • UMD (browser only)

Which has been roughly sufficient, as most Node projects can consume CJS (either because they’re written in CJS themselves, or can use a transpiler) and most browser-based projects can consume either ESM (via a transpiler) or load the UMD script tag.

It gets a bit trickier with the use of a tool like ts-node, which, as far as I understand, is transpiling your ESM Node source code on the fly with tsc into CommonJS, but which is expecting imported libraries to also be ESM.

The reason I haven’t provided an ESM-compatible Node version of the library so far is that Node also supports native ESM, but via the use of .mjs extensions, which (in the limited investigation I did) wrecked havoc with the existing build process.

That said, this is good motivation to pick that investigation back up, as you probably are not the only one who will run into that issue (and it’s weird to need a single require() tag amongst the other import tags).

0reactions
thekevinscottcommented, Dec 20, 2022

Awesome, great to hear!

One other thing I should have mentioned, because you’re in Node, you should experiment with providing an explicit model. I’d recommend either the 4x or 8x models from esrgan-thick (the 8x image is not shown, which is a bug in the documentation, but you should be able to import it). You can also explicitly specify the model you’re using now, GANS from esrgan-legacy.

The reason I recommend this is because UpscalerJS is using the default-model by default, which currently is the GANS model (slow and more precise) but which will be switching to the 2x esrgan-slim model (fast, less precise). For your use case, I think you probably want the most precise model.

Read more comments on GitHub >

github_iconTop Results From Across the Web

SyntaxError: Unexpected token - JavaScript - MDN Web Docs
The JavaScript exceptions "unexpected token" occur when a specific language construct was expected, but something else was provided.
Read more >
Have a JavaScript Unexpected Token Error? Check Your Syntax
The JavaScript's parser expects tokens and symbols in a particular order, with relevant values or variables in between. Often, an Unexpected ...
Read more >
syntax error: unexpected token - javascript - Stack Overflow
The error SyntaxError: Unexpected token < likely means the API endpoint didn't return JSON in its document body, such as due to a...
Read more >
JavaScript Error Handling: Unexpected Token - GeeksforGeeks
Not follow them throws an error.An unexpected token occurs if JavaScript code has a missing or extra character { like, ) + –...
Read more >
How to fix JavaScript unexpected token error
As you write your JavaScript application, the unexpected token error always occurs because JavaScript expected a specific syntax that's not ...
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