Vite and rollup browser error when importing library
See original GitHub issueI’m getting what looks like the symptom of a circular dependency when loading the ESM module in a browser.
Expected Behavior
Running the following code should import the ES module and not throw an error.
import * as filestack from "filestack-js";
Current Behavior
Running the following code:
import * as filestack from "filestack-js";
Raises the following error in the browser console:
Uncaught TypeError: Object prototype may only be an Object or null: undefined
at setPrototypeOf (<anonymous>)
at __extends (tslib.es6.js:25)
at http.ts:43
at node_modules/filestack-js/build/module/lib/request/adapters/http.js (http.ts:64)
at __init (filestack-js.js?v=7b23504f:14)
at request_adapter.node.ts:17
The problem is the usage of Stream.Writable
when defining a class in http.ts
. Stream.Writable
is undefined
. This would appear to be due to a circular dependency that rollup cannot resolve, but I’m not really sure.
Steps to Reproduce (for bugs)
Reproduction repo is https://github.com/taylorthurlow/filestack-rollup-repro - simple instructions can be found in the README. You will need ruby installed, I used Ruby 2.7. 2.5 and 2.6 should also be fine. This repo is basically a completely unmodified Rails application. The commit history is extremely short and shows what little I need to do to get this to happen.
Additional Screenshots
Context
I’m just trying to use the library with Vite, which uses rollup under the hood.
Your Environment
- Version used: 3.24.1
- Browser Name and version: Chrome 92 and Firefox 90.
- Operating System and version (desktop or mobile): macOS 11.5.2
Issue Analytics
- State:
- Created 2 years ago
- Comments:9
Top GitHub Comments
@taylorthurlow I was able to work around this same issue by importing the built esm directly:
Thanks! The fix I was looking for