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 #265

Closed
patrickinminneapolis opened this issue Aug 28, 2023 · 4 comments
Closed

Unexpected token #265

patrickinminneapolis opened this issue Aug 28, 2023 · 4 comments
Labels
question Further information is requested

Comments

@patrickinminneapolis
Copy link

I added this code to my React project.

import { pipeline } from "@xenova/transformers";

async function sentimentAnalysis() {
  // Allocate a pipeline for sentiment-analysis
  let pipe = await pipeline("sentiment-analysis");
  let out = await pipe("I love transformers!");
  console.log(out);
}

sentimentAnalysis();

I am surprised the docs don't tell me to download a model, so I think this code will auto-download it... anyway I get this issue...
./node_modules/@xenova/transformers/src/env.js 38:84
Module parse failed: Unexpected token (38:84)
File was processed with these loaders:

  • ./node_modules/babel-loader/lib/index.js
    You may need an additional loader to handle the result of these loaders.
    |
    | var RUNNING_LOCALLY = FS_AVAILABLE && PATH_AVAILABLE;

var __dirname = RUNNING_LOCALLY ? path.dirname(path.dirname(url.fileURLToPath(import.meta.url))) : './';
|
| // Only used for environments with access to file system

Seems like I need access to the filesystem... but that can't be right because this runs in the browser ... ?

@patrickinminneapolis patrickinminneapolis added the question Further information is requested label Aug 28, 2023
@xenova
Copy link
Owner

xenova commented Aug 28, 2023

Seems like I need access to the filesystem... but that can't be right because this runs in the browser ... ?

This is just a check to see if you're running in development mode (which is useful for me) - but this won't affect you.

Module parse failed: Unexpected token (38:84)

Regarding this error, could you note what version of node and npm you are using? Also, I am aware of people that use create-react-app experiencing issues with newer JS libraries. If you are using CRA, I would advise you migrate to a better build tool like Vite (see previous issues for more information on this).

@patrickinminneapolis
Copy link
Author

node v16.17.0 , npm 8.15.0 .... yes I am using CRA, I think, I'm extending another project and I assume it was built with create-react-app, but I don't have react-scripts in my package.json, so idk.

@xenova
Copy link
Owner

xenova commented Aug 28, 2023

node v16.17.0
yes I am using CRA

I would advise that you update to node >= 18.x (v16 is reaching EOL soon) and use Vite instead of CRA. I don't think I will be adding support for these older versions.

@patrickinminneapolis
Copy link
Author

It works in Vite with node 18 and npm 8.... now I just have to port my project over to it i guess

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

No branches or pull requests

2 participants