Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unexpected Token #554

Closed
imlanky opened this issue Oct 28, 2022 · 10 comments
Closed

Unexpected Token #554

imlanky opened this issue Oct 28, 2022 · 10 comments
Assignees

Comments

@imlanky
Copy link

imlanky commented Oct 28, 2022

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

SyntaxError: Unexpected token 'export'
@thekevinscott
Copy link
Owner

Can you provide a reproducible repository?

An issue like this is usually related to how your bundle or transpiler is set up. You're loading ESM code but whatever setup is complaining that it doesn't know how to handle it.

@thekevinscott
Copy link
Owner

Closing for now, feel free to reopen with a reproducible repo

@hollowshiroyuki
Copy link

Hello, reopening this issue with a reproducible repo https://github.com/hollowshiroyuki/Timi_OCR_Proto. I'm trying to increase TesseractJS results by upscaling before processing the picture. You need to uncomment lines 3, 6 and 17, and remove line 18 in index.ts.

Tested with :

  • tsc v4.9.3
  • node v19.2.0
  • ts-node v10.9.2

Quick way to test : npm run run <Image File>

Thanks for your assistance !

@thekevinscott
Copy link
Owner

@hollowshiroyuki I can’t access that repo - maybe it’s set to private?

@thekevinscott thekevinscott reopened this Dec 7, 2022
@hollowshiroyuki
Copy link

whoops sorry, it's fixed now 👍

@thekevinscott
Copy link
Owner

Thanks, I can see it now.

I’m on my phone and can check later, but at a glance - is this a Node.js project? If so you’ll need to import from node:

Import ‘upscaler/node’

check out the getting started docs section on node.

I’ll double check again when I’m front of my computer

@hollowshiroyuki
Copy link

This is indeed a nodejs project and I'm using Typescript.

I tried your suggestion but it didn't work, I'm not sure if it's a problem of the package or my typescript configuration.

I also tried using https://www.typescriptlang.org/docs/handbook/module-resolution.html#path-mapping without success.

{
  "compilerOptions": {
    "baseUrl": ".",
    "paths": {
      "upscaler": ["node_modules/upscaler/dist/node"],
    }
  }
}

@thekevinscott
Copy link
Owner

thekevinscott commented 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).

@hollowshiroyuki
Copy link

Indeed it works now, we got better recognition performance, thanks a lot !

@thekevinscott
Copy link
Owner

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants