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

fix(core): resolve webpack loaders with require.resolve() #3341

Merged
merged 1 commit into from
Jul 15, 2020

Conversation

elliottsj
Copy link
Contributor

@elliottsj elliottsj commented Jul 14, 2020

With strict package managers such as pnpm or Yarn PnP, transitive dependencies are not hoisted to the root node_modules folder. This means that a webpack config defined within a package like '@nrwl/cypress' cannot resolve loaders like 'ts-loader', unless 'ts-loader' is declared in the workspace's own package.json.

This is a problem because the workspace might define a different version of 'ts-loader', incompatible with the version declared by '@nrwl/cypress/package.json'. The workspace should not need to declare a dependency on 'ts-loader' anyway.

By using require.resolve(), Node.js's module resolution is used instead of webpack's, so this issue is avoided.

See also:

Current Behavior

Workspaces using pnpm must declare dependencies on loaders used by @nrwl/* packages, and manually keep the versions in sync. Or, a public-hoist-pattern must be defined to hoist webpack loaders.

Expected Behavior

pnpm users should not have to declare transitive dependencies or customize package hoisting.

With strict package managers such as pnpm or Yarn PnP, transitive
dependencies are *not* hoisted to the root node_modules folder. This
means that a webpack config defined within a package like
'@nrwl/cypress' cannot resolve loaders like 'ts-loader', unless
'ts-loader' is declared in the workspace's own package.json.

This is a problem because the workspace might define a different version
of 'ts-loader', incompatible with the version declared by
'@nrwl/cypress/package.json'. The workspace should not need to declare
a dependency on 'ts-loader' anyway.

See also:
* pnpm/pnpm#801
* webpack/webpack#5087
@jaysoo jaysoo merged commit d74ab4e into nrwl:master Jul 15, 2020
@elliottsj elliottsj deleted the resolve-webpack-loaders branch July 15, 2020 19:13
@jaysoo
Copy link
Member

jaysoo commented Jul 20, 2020

@elliottsj Going to have to revert this one since it is causing an issue with apps not being styled. I think you need to install PnpWebpackPlugin as well for require.resolve to work. Can you take a look again?

https://github.com/arcanis/pnp-webpack-plugin

You can test your changes locally by publishing to your local registry. https://github.com/nrwl/nx/blob/master/CONTRIBUTING.md#publishing-to-a-local-registry

@elliottsj
Copy link
Contributor Author

elliottsj commented Jul 27, 2020

@jaysoo Can you elaborate on the styling issue? Did it affect @nrwl/react?

I'm using pnpm rather than Yarn PnP, so the PnP webpack plugin is not applicable.

@jaysoo
Copy link
Member

jaysoo commented Aug 5, 2020

@elliottsj Basically styles were not applied, I'm guessing due to the loaders not being found but didn't debug too much. I'll check out your new PR. Thanks!

Doginal pushed a commit to Doginal/nx that referenced this pull request Nov 25, 2020
With strict package managers such as pnpm or Yarn PnP, transitive
dependencies are *not* hoisted to the root node_modules folder. This
means that a webpack config defined within a package like
'@nrwl/cypress' cannot resolve loaders like 'ts-loader', unless
'ts-loader' is declared in the workspace's own package.json.

This is a problem because the workspace might define a different version
of 'ts-loader', incompatible with the version declared by
'@nrwl/cypress/package.json'. The workspace should not need to declare
a dependency on 'ts-loader' anyway.

See also:
* pnpm/pnpm#801
* webpack/webpack#5087
Doginal pushed a commit to Doginal/nx that referenced this pull request Nov 25, 2020
@github-actions
Copy link

This pull request has already been merged/closed. If you experience issues related to these changes, please open a new issue referencing this pull request.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 22, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants