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

Unable to run package.json scripts using yarn #703

Closed
jebax opened this issue Jun 8, 2022 · 30 comments · Fixed by maizzle/cli#163
Closed

Unable to run package.json scripts using yarn #703

jebax opened this issue Jun 8, 2022 · 30 comments · Fixed by maizzle/cli#163

Comments

@jebax
Copy link

jebax commented Jun 8, 2022

  • Maizzle Version: 4.0.0
  • Node.js Version: 16.5.3

Hi,

As of maizzle 4.0.0 there's a problem executing package.json scripts that use the maizzle command, IF you're using yarn instead of npm:

yarn run v1.22.10
$ maizzle build production
env: node\r: No such file or directory
error Command failed with exit code 127.

To reproduce:

  1. Create a new starter project: maizzle new
  2. Delete package-lock.json and run yarn install
  3. Run yarn dev or yarn build

Thanks!

@cossssmin
Copy link
Member

Sounds like a yarn problem, have you tried doing npm install first?

@jebax
Copy link
Author

jebax commented Jun 9, 2022

Sounds like a yarn problem, have you tried doing npm install first?

Not sure what you mean with this. I'm using yarn, so I run yarn install to generate a yarn.lock rather than npm install. Then after running yarn install I try and run yarn dev or yarn build and those commands break. I've tested this across various laptops and all of them break when using maizzle 4.0.0 starter project + yarn.

@cossssmin
Copy link
Member

I meant to say yarn may be caching some stuff, not really sure since I don't use it. There's nothing special that we do for npm and since yarn uses npm there must be something that we'd need to do for it instead, just don't know what 🤔

@jebax
Copy link
Author

jebax commented Jun 9, 2022

I meant to say yarn may be caching some stuff, not really sure since I don't use it. There's nothing special that we do for npm and since yarn uses npm there must be something that we'd need to do for it instead, just don't know what 🤔

I've tried deleting node_modules, running yarn cache clean then yarn install again and still get the same problem, so doesn't seem like it's a problem specific to my machine / setup

@gyto
Copy link

gyto commented Jun 10, 2022

+1 Having the same issue with serving via yarn and npm

npm run dev

> dev
> maizzle serve

env: node\r: No such file or directory
yarn dev     
yarn run v1.22.17
$ maizzle serve
env: node\r: No such file or directory
error Command failed with exit code 127.

@cossssmin
Copy link
Member

cossssmin commented Jun 10, 2022

@gyto and @jebax what operating system are you using?

I wonder if it could be because of line endings 🤔

Reference:

npm/npm#12371

yarnpkg/yarn#5480

@cossssmin
Copy link
Member

Also, do you have the Maizzle CLI installed globally?

Just tested on a Mac that didn't have anything Maizzle-related installed and both scripts are working as expected.

@cossssmin
Copy link
Member

cossssmin commented Jun 10, 2022

Think I may found the issue, but will need your help to confirm.

Can you please open node_modules/@maizzle/framework/bin/maizzle in your editor and try to save it so that it has LF line endings?

For example, in VS Code it shows it in the bottom status bar, on the right side:

Then try running npm run dev again, should work I think.

That's the executable used when running the npm scripts, and I see it had CRLF line endings, so that might be the culprit. Just need to confirm since I can't reproduce it on my end, thanks!

@jebax
Copy link
Author

jebax commented Jun 10, 2022

Think I may found the issue, but will need your help to confirm.

Can you please open node_modules/@maizzle/framework/bin/maizzle in your editor and try to save it so that it has LF line endings?

For example, in VS Code it shows it in the bottom status bar, on the right side:

Then try running npm run dev again, should work I think.

That's the executable used when running the npm scripts, and I see it had CRLF line endings, so that might be the culprit. Just need to confirm since I can't reproduce it on my end, thanks!

Just tried this and changing to LF does get me past the error I was seeing!

However now I get Error: Cannot find module '@maizzle/cli' (which I have in my dev dependencies btw).

@cossssmin
Copy link
Member

OK, we're getting there :)

You don't need @maizzle/cli in your devDependencies, it now comes included with the framework. Try uninstalling it and running the script again. If you have the CLI also installed globally, try uninstalling it from there too with npm uninstall -g @maizzle/cli (you can reinstall it later if you need to).

@jebax
Copy link
Author

jebax commented Jun 10, 2022

OK, we're getting there :)

You don't need @maizzle/cli in your devDependencies, it now comes included with the framework. Try uninstalling it and running the script again. If you have the CLI also installed globally, try uninstalling it from there too with npm uninstall -g @maizzle/cli (you can reinstall it later if you need to).

Tried this but it hasn't helped unfortunately. Have uninstalled maizzle globally, deleted node modules, cleared the yarn cache, and installed again.

Can only get the commands to work by replacing require('@maizzle/cli') with require('../../cli/bin/maizzle')

@cossssmin
Copy link
Member

Have you also removed package-lock.json and/or yarn.lock? Without that it would just reinstall the same dependencies in the same way. It's complaining about a missing dependency, which shouldn't be the case.

@jebax
Copy link
Author

jebax commented Jun 10, 2022

Have you also removed package-lock.json and/or yarn.lock? Without that it would just reinstall the same dependencies in the same way. It's complaining about a missing dependency, which shouldn't be the case.

Yeah I removed yarn.lock as well as node_modules

@cossssmin
Copy link
Member

Hmm no other ideas for now, except to blame yarn 🙈

Need to check this with more users to ensure it's not some strange edge case and find out what's causing it...

@cossssmin
Copy link
Member

cossssmin commented Jun 10, 2022

@jebax what npm version are you using?

Could you try updating to latest with npm install npm@latest -g and testing again? Just had someone report npm run dev was failing and they were using [email protected] - they just updated it and got it working.

Not sure if it can also be caused by nvm and the way it adds executables to $PATH 🤔

EDIT: just had someone help test it on a macOS machine that didn't even had Node - installed the LTS, then followed the installation docs and npm run dev worked as expected. Keeping this open to try and get to the bottom of it, but I'm starting to think its a setup issue.

@JoeyEamigh
Copy link

Getting the same issue using a yarn-based turborepo monorepo on Linux. Let me know if there is any info I can provide to help debug this!

@jebax
Copy link
Author

jebax commented Jun 13, 2022

@jebax what npm version are you using?

Could you try updating to latest with npm install npm@latest -g and testing again? Just had someone report npm run dev was failing and they were using [email protected] - they just updated it and got it working.

Not sure if it can also be caused by nvm and the way it adds executables to $PATH 🤔

EDIT: just had someone help test it on a macOS machine that didn't even had Node - installed the LTS, then followed the installation docs and npm run dev worked as expected. Keeping this open to try and get to the bottom of it, but I'm starting to think its a setup issue.

tried upgrading to the latest npm but didn't help, still get Error: Cannot find module '@maizzle/cli' after changing the line endings to LF, or the env: node\r: No such file or directory if I leave it as-is.

RE: your comment about someone trying with a fresh install - do you mean yarn run dev? the issue isn't with npm run dev for me, that command has always worked fine

@mzgajner
Copy link

Can confirm the issue, my reproduction flow:

  • maizzle wasn't installed globally
  • Followed the getting started guide, everything works as expected using npm.
  • Once I install packages with yarn, errors start occurring when running npm run dev.
  • Errors don't go away even if I delete yarn.lock and run npm install.
  • Only thing that fixes it is deleting node_modules and reinstalling with npm install.

Versions:

  • yarn 1.22.19
  • npm 8.5.5
  • node 16.15.0

@v1k45
Copy link

v1k45 commented Jun 15, 2022

I am seeing the same issue after upgrading to 4.0.0.

yarn run v1.22.18
$ maizzle serve
env: node\r: No such file or directory
error Command failed with exit code 127.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

I also tried deleting node_modules, it didn't work.

@cossssmin
Copy link
Member

Hmm, I wonder if this is also an issue with yarn 2 - I see everyone reporting it is running v1.x

@cossssmin
Copy link
Member

OK so I just gave yarn 1.22.15 a try and I was able to reproduce the issue where it failed to find the maizzle executable. Didn't get the line ending error though.

I then removed package-lock.json and reinstalled dependencies with npm install (so not through yarn), and was able to get yarn dev running perfectly fine. I'm on Windows 11, Node 16.13.2, npm 8.4.0.

@jebax
Copy link
Author

jebax commented Jun 15, 2022

OK so I just gave yarn 1.22.15 a try and I was able to reproduce the issue where it failed to find the maizzle executable. Didn't get the line ending error though.

I then removed package-lock.json and reinstalled dependencies with npm install (so not through yarn), and was able to get yarn dev running perfectly fine. I'm on Windows 11, Node 16.13.2, npm 8.4.0.

this works for me, however the problem is that I want to manage my dependencies with yarn, not just execute the scripts. I guess there must be something about the require('@maizzle/cli') line that seems to be incompatible with yarn (aside from the line endings bug, which i'm assuming you aren't getting because you're on windows).

@cossssmin
Copy link
Member

cossssmin commented Jun 15, 2022

Yeah, not sure what we can do about that, I kinda doubt it's because of that require, as it's actually complaining about not being able to find the bin (which is definitely there, and yarn itself can find it if you run yarn bin maizzle in the project root).

I'll leave this open for now in case anyone comes up with a solution 👍

@v1k45
Copy link

v1k45 commented Jun 15, 2022

I then removed package-lock.json and reinstalled dependencies with npm install (so not through yarn), and was able to get yarn dev running perfectly fine. I'm on Windows 11, Node 16.13.2, npm 8.4.0.

Using npm worked for me. I am on Mac, Node 14, npm 6.

You don't need @maizzle/cli in your devDependencies, it now comes included with the framework.

For some reason the framework dependency on its own didn't work. Had to manually install @maizzle/cli to make it work.

@dzcpy
Copy link

dzcpy commented Jun 20, 2022

Same problem here. After installing with yarn there is an error running yarn dev

$ yarn dev // or npm run dev

> dev
> maizzle serve

node:internal/modules/cjs/loader:936
  throw err;
  ^

Error: Cannot find module '@maizzle/cli'
Require stack:
- /srv/node_modules/@maizzle/framework/bin/maizzle
    at Function.Module._resolveFilename (node:internal/modules/cjs/loader:933:15)
    at Function.Module._load (node:internal/modules/cjs/loader:778:27)
    at Module.require (node:internal/modules/cjs/loader:1005:19)
    at require (node:internal/modules/cjs/helpers:102:18)
    at Object.<anonymous> (/srv/node_modules/@maizzle/framework/bin/maizzle:3:1)
    at Module._compile (node:internal/modules/cjs/loader:1101:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
    at Module.load (node:internal/modules/cjs/loader:981:32)
    at Function.Module._load (node:internal/modules/cjs/loader:822:12)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [
    '/srv/node_modules/@maizzle/framework/bi/maizzle'
  ]
}

Even adding @maizzle/cli manually won't fix this issue

Also tried pnpm and not working as well

@dzcpy
Copy link

dzcpy commented Jun 20, 2022

One possible reason is that in @maizzle/cli's package.json there is no "main" attribute, so even you requires it, node.js doesn't know what to execute.

@cossssmin
Copy link
Member

Released v4.0.2, let me know if it's working for you now 👍

@mzgajner
Copy link

Works! ❤️

@jebax
Copy link
Author

jebax commented Jun 21, 2022

works! thanks 🙏

@cossssmin
Copy link
Member

Cool, thanks for confirming 👍

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

Successfully merging a pull request may close this issue.

7 participants