-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
Yarn v2 installation error Usage Error: Couldn't find the node_modules state file - running an install might help (findPackageLocation) #907
Comments
having the same issue, any insight into this? |
It seems like when we define |
adding a note for devs in the future with similar headaches... it was a sub project, which was a git submodule and a yarn workspace, configured as fixed by removing |
I was running into the same issue and came across this workaround: yarnpkg/berry#2701 (comment) It uses a yarn plugin and hook to allow particular scripts to run without the expected node_modules state. For example, we needed a // .yarn/plugins/override-state.js
const ALLOWED_SCRIPTS = ['heroku-prebuild'];
const NODE_MODULES = 'node_modules';
const STATE_FILE = '.yarn-state.yml';
module.exports = {
name: `plugin-override-state`,
factory: require => ({
hooks: {
async setupScriptEnvironment(project, scriptEnv) {
if (
scriptEnv != null &&
ALLOWED_SCRIPTS.find(
script => script == scriptEnv.npm_lifecycle_event,
) != null
) {
if (project.configuration.get(`nodeLinker`) === `node-modules`) {
const stateFile = [project.cwd, NODE_MODULES, STATE_FILE].join('/');
const fs = require('fs');
if (!fs.existsSync(stateFile)) {
console.log(
'Detected command allowed in stateless environment and state file is missing.',
);
console.log('Generating empty state file...');
fs.mkdirSync(require('path').dirname(stateFile), {
recursive: true,
});
fs.appendFileSync(stateFile, '# Autogenerated\n', { flag: 'w+' });
fs.appendFileSync(stateFile, '__metadata:\n');
fs.appendFileSync(stateFile, ' version: 1\n');
fs.appendFileSync(stateFile, ' nmMode: classic\n');
}
}
}
},
},
}),
}; Enabled with # .yarnrc.yml
plugins:
- .yarn/plugins/override-state.js |
@ferm10n why is using |
I had this issue while trying to run Storybook in Backstage repo, fixed it by running the install command directly inside the Storybook folder, not sure why that is the only one that breaks given that we have many plugins that work with just the root install. |
* this should solve the problem with non-existing node modules state file * @see: heroku/heroku-buildpack-nodejs#907
* this should solve the problem with non-existing node modules state file * @see: heroku/heroku-buildpack-nodejs#907
* this should solve the problem with non-existing node modules state file * @see: heroku/heroku-buildpack-nodejs#907
I still get this error with yarn 4. I do not have a monorepo which could have conflicting module resolving settings. I'm using prebuild to set up npm credentials using yarn and get the exact same error as @jasonlimantoro Is there any other workaround? |
@robertmaier without knowing the particulars of how you're setting up the credentials, some options could be: Use
|
Describe the bug
Using Yarn v2 workspace (node_modules linker, not PnP), the build will fail if
heroku-prebuild
is defined in the rootpackage.json
To Reproduce
Steps to reproduce the behavior:
heroku-prebuild
script in root package.json.The script could be as simple as:
git push heroku main
ordpl --provider=heroku
, it doesn't matter)Versions (please complete the following information):
heroku-20
14.x
2.4.0
Additional context
heroku-prebuild
is not defined, the installation always works.NODE_MODULES_CACHE
has been disabled or enabled, the error persists.NPM_CONFIG_PRODUCTION
andYARN_PRODUCTION
has been unset as per the official migration guide, the error still persistsheroku-prebuild
script (suggesting that maybe it wasn't even run)Log output (trimmed):
The text was updated successfully, but these errors were encountered: