liferay / liferay-frontend-projects

A monorepo containing assorted Frontend Infrastructure Team projects
Other
69 stars 68 forks source link

Error when calling @liferay/npm-bundler with npx #217

Closed p2kmgcl closed 3 years ago

p2kmgcl commented 3 years ago

Issue type

Description

(Linked Jira issue https://issues.liferay.com/browse/LPS-122795) (Reviewed with @izaera)

Desired behavior: call @liferay/npm-bundler with npx (npx @liferay/npm-bundler).

Current behavior: when the command is run, an error is shown in the console: image

Repro instructions (if applicable):

Other information (environment, versions etc):

wincent commented 3 years ago
  • It might be the reference to the binary file in package.json (bundler vs angular)

Seems like a reasonable guess. In @liferay/npm-scripts we use the dot-relative form and it works fine.

wincent commented 3 years ago

Just to clarify, @p2kmgcl — I see you tested this on Linux and Windows, but the linked LPS only mentions Windows. Does that mean it works on Linux and not on Windows?

p2kmgcl commented 3 years ago

Nope, I tested on Windows for the LPS and then I found that it doesn't work on Linux too (thanks to @izaera). I am going to update the Jira ticket :sweat_smile:

izaera commented 3 years ago

I'm getting a different error in Windows:

image

This has nothing to do with what I tried to fix in this PR, i.e.: it has a different solution. I need to make sure what is really happening: whether this is the real error, or if there are two different errors that need to be addressed separately.

Can you check again @p2kmgcl ?

p2kmgcl commented 3 years ago

The steps are:

  1. Create an empty directory
  2. cd into it and run yarn init (yes to everything)
  3. Add yarn add -D generator-liferay-fragments@next (which has @liferay/npm-bundler@3.0.1-pre.1 as dependency)
  4. Run npx @liferay/npm-bundler
p2kmgcl commented 3 years ago

Ok, after testing this on Windows, Linux, different computer and different npx versions (6 and 7 to be precise) I think that npx is more fragile than what I thought on the first place (too much magic :unicorn:). I just merged this change removing the npx call and looking for the liferay-npm-bundler.js file manually.

@izaera suggested replacing this path.resolve with a require.resolve to better find where the node_modules directory is, but that's something I'll do tomorrow (because I'm tired).

Anyway, thanks @wincent and @izaera for your time and sorry for the npx headache, I'm closing the issue.

:rainbow:

izaera commented 3 years ago

See https://github.com/liferay/liferay-frontend-projects/pull/220 too

izaera commented 3 years ago

(because I'm tired).

sloth