Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Uncaught TypeError: Object prototype may only be an Object or null: undefined #26

Open
forgetso opened this issue Mar 30, 2022 · 3 comments

Comments

@forgetso
Copy link

forgetso commented Mar 30, 2022

Hi, when we try to use polyfill in our project we get the following error in the browser. Any ideas how this can be resolved or how to debug it?

Uncaught TypeError: Object prototype may only be an Object or null: undefined
    at Function.setPrototypeOf (<anonymous>)
    at polyfills.js:139
    at patch (polyfills.js:141)
    at patch (graceful-fs.js:104)
    at Object.../../../../node_modules/graceful-fs/graceful-fs.js (graceful-fs.js:96)
    at Object.options.factory (react refresh:6)
    at __webpack_require__ (bootstrap:24)
    at fn (hot module replacement:61)
    at Object.../../../../node_modules/fs-extra/lib/fs/index.js (index.js:5)
    at Object.options.factory (react refresh:6)

It seems to relate to this line in polyfill:

    // This ensures `util.promisify` works as it does for native `fs.read`.
    if (Object.setPrototypeOf) Object.setPrototypeOf(read, fs$read)`

fs$read here is undefined

@Richienb
Copy link
Owner

The location of the original polyfill will need to be tracked down and a test will probably need to be made in order to fix it.

@FreedomRings
Copy link

FreedomRings commented Apr 6, 2022

Perhaps I can help narrow the search. I came here looking for a solution after including the resolve fallbacks below in my custom-webpack (to solve the webpack 5 problems) and ended up with the same error as the OP. I highly suspected FS was the issue since that appears to be our commonality, and when I chased it down, it is the fs read that the problem occurs.

resolve: {
        fallback: {
            "path": require.resolve("path-browserify"),
            "stream": require.resolve("stream-browserify"),
            "constants": require.resolve("constants-browserify"),
            "util": require.resolve("util"),
            "process": require.resolve("process/browser"),
            "fs": require.resolve("graceful-fs")
        }
    }

The failing instruction in the function patch (fs) and it reads:
Uncaught TypeError: Object prototype may only be an Object or null: undefined:

The failing line is at the end of the fs.read function:

    // This ensures `util.promisify` works as it does for native `fs.read`.
    if (Object.setPrototypeOf) Object.setPrototypeOf(read, fs$read)

@Richienb
Copy link
Owner

This module doesn't provide a polyfill for fs because it is not possible to precisely mimic that level of filesystem control in the browser. The code you are compiling should be made more platform-agnostic.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants