Generating bundle.js error "SyntaxError: Unexpected token" with transformers.js package

Hi everyone! I have this error when i’m trying to generate bundle.js with browserify. This error happens just by importing package like import { pipeline, env } from "@xenova/transformers"; Maybe someone can give me recomendations how to fix that?
build command:

browserify ./src/index.js -o ./dist/bundle.js -t [ babelify --global --presets [@babel/preset-env] --extensions \".js\",\".jsx\"  ]

.babelrc :

{
  "presets": [["@babel/preset-env", {
    "targets": "> 0.25%, not dead",
    "useBuiltIns": "usage",
    "corejs": 3
  }]]
}

error:

> browserify ./src/index.js -o ./dist/bundle.js -t [ babelify --global --presets [@babel/preset-env] --extensions ".js",".jsx"  ] 

SyntaxError: Unexpected token (45:119) while parsing C:\Users\Artur\Documents\data_source_analyzer\assets\client_data_source_analyzer\node_modules\@xenova\transformers\src\env.js while parsing file: C:\Users\Artur\Documents\data_source_analyzer\assets\client_data_source_analyzer\node_modules\@xenova\transformers\src\env.js
    at DestroyableTransform.end [as _flush] (C:\Users\Artur\Documents\data_source_analyzer\assets\client_data_source_analyzer\node_modules\insert-module-globals\index.js:114:21)
    at DestroyableTransform.prefinish (C:\Users\Artur\Documents\data_source_analyzer\assets\client_data_source_analyzer\node_modules\insert-module-globals\node_modules\readable-stream\lib\_stream_transform.js:138:10)
    at DestroyableTransform.emit (node:events:518:28)
    at prefinish (C:\Users\Artur\Documents\data_source_analyzer\assets\client_data_source_analyzer\node_modules\insert-module-globals\node_modules\readable-stream\lib\_stream_writable.js:619:14)
    at finishMaybe (C:\Users\Artur\Documents\data_source_analyzer\assets\client_data_source_analyzer\node_modules\insert-module-globals\node_modules\readable-stream\lib\_stream_writable.js:627:5)
    at endWritable (C:\Users\Artur\Documents\data_source_analyzer\assets\client_data_source_analyzer\node_modules\insert-module-globals\node_modules\readable-stream\lib\_stream_writable.js:638:3)
    at Writable.end (C:\Users\Artur\Documents\data_source_analyzer\assets\client_data_source_analyzer\node_modules\insert-module-globals\node_modules\readable-stream\lib\_stream_writable.js:594:22)
    at BabelifyStream.onend (node:internal/streams/readable:946:10)
    at Object.onceWrapper (node:events:632:28)
    at BabelifyStream.emit (node:events:518:28)
    at endReadableNT (node:internal/streams/readable:1696:12)
    at process.processTicksAndRejections (node:internal/process/task_queues:82:21)```

cc @Xenova might be able to help here

I have already solved it) Solution: vite + babel/preset-env

1 Like

This topic was automatically closed 12 hours after the last reply. New replies are no longer allowed.