Skip to content

Can't resolve 'global/window' (webpack) #21

@fregante

Description

@fregante
ERROR in ./node_modules/my-module/index.js 2:28-34
Module not found: Error: Can't resolve 'global/window' in './node_modules/my-module'
Did you mean 'window.js'?
BREAKING CHANGE: The request 'global/window' failed to resolve only because it was resolved as fully specified
(probably because the origin is a '*.mjs' file or a '*.js' file where the package.json contains '"type": "module"').
The extension in the request is mandatory for it to be fully specified.
Add the extension to the request.

This appears to be because global/window is not a valid identifier in ES modules so every single example on the web fails:

    new webpack.ProvidePlugin({
      window: "global/window",
      document: "global/document",
    }),

Thankfully in this case the solution was:

    new webpack.ProvidePlugin({
      window: "global/window.js",
      document: "global/document.js",
    }),

This might be fixable with export maps in package.json, but I'm not entirely sure.

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