Skip to content

Webpack: Can't resolve 'fs' #4

Open
@tessereth

Description

@tessereth

I tried pulling in this npm package and compiling it with webpack but I get the following errors:

ERROR in ./node_modules/micropython/index.js
Module not found: Error: Can't resolve 'fs' in './micropython_example/node_modules/micropython'
 @ ./node_modules/micropython/index.js 21:9-22
 @ ./assets/js/app.js
 @ ./assets/js/index.js

ERROR in ./node_modules/micropython/lib/micropython.js
Module not found: Error: Can't resolve 'fs' in './micropython_example/node_modules/micropython/lib'
 @ ./node_modules/micropython/lib/micropython.js 39:15-28 80:13-26 179:28-41 3005:23-36
 @ ./node_modules/micropython/index.js
 @ ./assets/js/app.js
 @ ./assets/js/index.js

This appears to be because webpack is not detecting that it can never go down the "node-only" path and still trying to require fs. If I add typeof __webpack_require__ !== 'function' on every branch that requires fs, everything works. But I don't know enough about webpack to be confident such changes are a good idea and/or they wouldn't break it for someone else.

You can see my webpack version and config and a working example at https://github.com/tessereth/micropython_wasm_example.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions