You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I can't reproduce this with the exact steps above, but I can reproduce this when the code is run in the global scope instead of in a module (note the change from new p.Path to new Path, which I assume is a typo):
$ cat entry.js
import { Path } from 'path-parser'
const path = new Path('/users/:id')
console.log(path.test('/users/00123'))
$ esbuild --bundle entry.js --platform=node | node
[stdin]:1216
var path = new import_path_parser.Path("/users/:id");
^
TypeError: Cannot read property 'Path' of undefined
The problem appears to be that the tslib library mutates the value of the __exportStar symbol in the global scope and overwrites esbuild's internal code with code that has different behavior. The difference between import and require is that import calls esbuild's __exportStar function while require does not.
Can you confirm whether you are running your code in the global scope or not? If so, one solution could be to not run your code in the global scope, either by saving it to a file and running it or by using --format=iife to wrap your code in a closure. Setting --platform=node implicitly sets --format=cjs which expects the code to be running inside a CommonJS closure, which is not in the global scope.
Found strange behaviour: when I'm trying to import path-parser as ES6 module
then after bundling I get runtime error
I think it is somehow connected to the way path-parser imports tslib. However, if I require path-parser as cjs module
then eveything works.
Or maybe because tslib has different entries for es6 and cjs.
The text was updated successfully, but these errors were encountered: