ts-morph icon indicating copy to clipboard operation
ts-morph copied to clipboard

Support loading ts-morph via esm.sh

Open paulshen opened this issue 3 years ago • 5 comments

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.

paulshen avatar Mar 23 '21 16:03 paulshen

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.

dsherret avatar Mar 23 '21 19:03 dsherret

makes sense. thanks for your work on this! 🙏

paulshen avatar Mar 24 '21 05:03 paulshen

Are there any plans to provide an ESM build anytime soon? @dsherret

schickling avatar Sep 04 '21 16:09 schickling

@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";)

dsherret avatar Sep 04 '21 16:09 dsherret

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.

dsherret avatar Sep 04 '21 16:09 dsherret