ts-morph
ts-morph copied to clipboard
Support loading ts-morph via esm.sh
Describe the bug
Version: 10.0.2
When loading [email protected] in the browser via ESM import, it gives an error "require is not defined", pointing at this.fs = require("fs")
.
If you pin to [email protected], it works fine.
To Reproduce
https://codesandbox.io/s/stoic-dewdney-blqc3?file=/index.html
The sandbox shows the error. If you change the 10.0.2
to 10.0.1
inside index.html
and reload the output, it works.
Expected behavior
You can load ts-morph in the browser from a ES module CDN.
It's just by chance that this used to work. I'd recommend using 10.0.1 for now, but probably that will not work for certain features.
makes sense. thanks for your work on this! 🙏
Are there any plans to provide an ESM build anytime soon? @dsherret
@schickling I believe you should be able to just use the deno.land/x urls instead of using esm.sh. Let me know if it doesn't work:
https://github.com/dsherret/ts-morph/tree/latest/deno#ts_morph
(You can specify a version on those by adding @x.x.x
after ts_morph
. Ex. import { Project } from "https://deno.land/x/[email protected]/mod.ts";
)
Oh, wait... I forgot that's a .ts
file and won't work in the browser. I'll look into changing the release so this can work.