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

Cannot find node-sass in Yarn workspace #84

Closed
swansontec opened this issue Mar 13, 2018 · 2 comments
Closed

Cannot find node-sass in Yarn workspace #84

swansontec opened this issue Mar 13, 2018 · 2 comments

Comments

@swansontec
Copy link
Contributor

I am using Yarn workspaces, which allows several projects to live in the same Git repository and share a common node_modules folder:

node_modules/
package.json
packages/
  some-library/
    package.json
    rollup.config.js
  another-library/
    package.json
    rollup.config.js

When I try to run rollup within another-library, the rollup-plugin-postcss plugin complains that it cannot find packages/another-library/node_modules/node-scss, which doesn't exist. This is because the node_modules directory isn't inside another-library, but two levels up from us.

Possible Solutions

It looks like the localRequire function is to blame, since it is hard-coded to only look in the current working directory:

const localRequire = name => require(path.resolve('node_modules', name))

One solution might be to have localRequire fall back on normal require if there's an issue:

const localRequire = name => {
  try {
    return require(path.resolve('node_modules', name))
  } catch (e) {
    return require(name)
  }
}

This would be a quick & dirty fix. Otherwise, maybe just ditching localRequire and using normal require might work, on the grounds that rollup-plugin-postcss and node-sass should be installed to the same place anyhow. Another option is enhance localRequire using the node-resolve package, so it will accurately search for the node_modules directory starting in the current working directory.

@egoist
Copy link
Owner

egoist commented Mar 14, 2018

@swansontec
Copy link
Contributor Author

Release 1.3.4 has the fix, so this is resolved now. Thanks a lot!

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

2 participants