Support loading ts-morph via esm.sh
See original GitHub issueDescribe the bug
Version: 10.0.2
When loading ts-morph@10.0.2 in the browser via ESM import, it gives an error “require is not defined”, pointing at this.fs = require("fs")
.
If you pin to ts-morph@10.0.1, 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.
Issue Analytics
- State:
- Created 2 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
ije/esm.sh: A fast, global content delivery network for ... - GitHub
This only works when the NPM module imports CSS files in JS directly. Web Worker. esm.sh supports ?worker mode to load modules as...
Read more >Bountysource
Support loading ts-morph via esm.sh. ... Help and Information. Frequently Asked Questions · Bugs and Feature Requests · Fees ...
Read more >Monorepo for Ts-morph and Related Projects - Morioh
import { createWrappedNode, ClassDeclaration, ts } from "ts-morph"; // some code that creates a class declaration using the ts object const classNode: ts....
Read more >File System - ts-morph
In most scenarios, you won't have to bother with what's outlined here, but it may be useful in some scenarios (for example, using...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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.@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
afterts_morph
. Ex.import { Project } from "https://deno.land/x/ts_morph@12.0.0/mod.ts";
)