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

Error: get-installed-path: module not found "@xmldom/xmldom" in path /home/abc/npm_temp/node_modules/apigeelint/node_modules/@xmldom/xmldom #471

Closed
brian-corcoran1 opened this issue Sep 20, 2024 · 13 comments
Assignees

Comments

@brian-corcoran1
Copy link

when running apigeelint cli.js run -s ./apiproxy -f tap.js seeing the error mentioned in the title. If I look in the lib/package/myUtils.js the following code looks to be the issue
const path = require("path"),
myhome = path.resolve(__dirname, "../../"),

if I change the path.resolve to path.resolve(__dirname, "../../../..") with 3 slashes it works.

@DinoChiesa
Copy link
Collaborator

what version of apigeelint are you using?
I think that problem is fixed in the latest version. v2.56.1

@brian-corcoran1
Copy link
Author

we are using 2.56.1

in 2.56.1 it is the same as 2.56.0
const path = require("path"),
myhome = path.resolve(__dirname, "../../"),

The path.resolve should have an extra slash.
myhome = path.resolve(__dirname, "../../../..")

@ssvaidyanathan
Copy link
Collaborator

I tested it using

apigeelint -s ./apiproxy -f table.js

and

./cli.js run -s ./apiproxy -f table.js

Both worked for me.

My versions:

node -v; npm -v; apigeelint --version
v20.17.0
10.8.3
2.56.1

@brian-corcoran1
Copy link
Author

ok. We are running in maven using ${user.home}/npm_temp/node_modules/apigeelint/cli.js run -s ./apiproxy -f tap.js

@ssvaidyanathan
Copy link
Collaborator

ssvaidyanathan commented Sep 20, 2024

Still not sure why thats happening, probably something to do with your file system?

can you run it as a npm run command instead?

For example, include the the scripts section to your package.json

"scripts": {
		"lint": "apigeelint -s apiproxy -e PO013,PO025 -f table.js"
	}

And then call npm run lint from Maven ?

@brian-corcoran1
Copy link
Author

brian-corcoran1 commented Sep 23, 2024

I've run the following on 2.55.3 and it works and on the latest it is not working.

c:\project-workspace>npm install.
c:\project-workspace\node_modules\apigeelint>node cli.js run -s C:\project-workspace\apiproxy -f tap.js

with 2.55.3 it works fine.

with the latest version I see the following error.
C:\project-workspace\node_modules\get-installed-path\dist\index.js:164
throw new Error(msg);
Error: get-installed-path: module not found "@xmldom/xmldom" in path C:\project-workspace\node_modules\apigeelint\node_modules@xmldom\xmldom
at getInstalledPathSync (C:\project-workspace\node_modules\get-installed-path\dist\index.js:164:11)
at Object. (C:\project-workspace\node_modules\apigeelint\lib\package\myUtil.js:30:16)

node version
v21.0.0

npm version
10.2.0

any help is appreciated.

@ssvaidyanathan
Copy link
Collaborator

@DinoChiesa - can you look into this? Could this be due to #464 ??

@DinoChiesa
Copy link
Collaborator

DinoChiesa commented Sep 24, 2024

@brian-corcoran1 can you try this?
https://github.com/DinoChiesa/apigeelint/tree/xmldom-resolution

If this corrects your problem we can merge #474

@brian-corcoran1
Copy link
Author

brian-corcoran1 commented Sep 24, 2024

this is what I am seeing now.

C:\project-workspace>node C:\project-workspace\node_modules\apigeelint\cli.js run -s ./apiproxy -f tap.js
C:\project-workspace\node_modules\apigeelint\lib\package\myUtil.js:49
throw new Error("cannot find node_modules");
^

Error: cannot find node_modules
at getNodeModulesPathFor (C:\project-workspace\node_modules\apigeelint\lib\package\myUtil.js:49:11)
at C:\project-workspace\node_modules\apigeelint\lib\package\myUtil.js:219:22
at Object. (C:\project-workspace\node_modules\apigeelint\lib\package\myUtil.js:224:3)
at Module._compile (node:internal/modules/cjs/loader:1369:14)
at Module._extensions..js (node:internal/modules/cjs/loader:1427:10)
at Module.load (node:internal/modules/cjs/loader:1201:32)
at Module._load (node:internal/modules/cjs/loader:1017:12)
at Module.require (node:internal/modules/cjs/loader:1229:19)
at require (node:internal/modules/helpers:177:18)
at Object. (C:\project-workspace\node_modules\apigeelint\lib\package\Resource.js:18:16)

I am running on windows and found how to resolve it. The const found = ["../../", "../../../"].reduce(r, null); statement has the slashes at the end that is not resolving to the directory on windows. If I remove the end slash in the found statement it resolves to the path to xmldom, const found = ["../..", "../../.."].reduce(r, null);

@DinoChiesa
Copy link
Collaborator

ok -as you can tell I did not test this on a windows machine.
Try now (with latest push of that branch) ?

(same edit as you suggested)

@DinoChiesa
Copy link
Collaborator

ok I'm just going to submit this PR, on the assumption that it's going to work.

@ssvaidyanathan
Copy link
Collaborator

released in v2.57.0

@feliperuiz
Copy link

Hey, @ssvaidyanathan and/or @DinoChiesa, I was trying to update apigeelint in a project for my day job and noticed that a very similar issue still persists in v2.57.0. We're using yarn, if that helps in any way.

I tried the following combinations of yarn and node versions, to no avail:

  • node 18.20.1, yarn 4.4.0
  • node 18.20.1, yarn 4.5.0
  • node 21.7.2, yarn 4.4.0
  • node 21.7.2, yarn 4.5.0

In all cases, this is the output I get:

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

Error: Cannot find module '<PATH TO PROJECT>/node_modules/apigeelint/node_modules/@xmldom/xmldom/lib/dom.js'
Require stack:
- <PATH TO PROJECT>/node_modules/apigeelint/lib/package/myUtil.js
- <PATH TO PROJECT>/node_modules/apigeelint/lib/package/Resource.js
- <PATH TO PROJECT>/node_modules/apigeelint/lib/package/Bundle.js
- <PATH TO PROJECT>/node_modules/apigeelint/lib/package/bundleLinter.js
- <PATH TO PROJECT>/node_modules/apigeelint/cli.js
  at Module._resolveFilename (node:internal/modules/cjs/loader:1140:15)
  at Module._load (node:internal/modules/cjs/loader:981:27)
  at Module.require (node:internal/modules/cjs/loader:1231:19)
  at require (node:internal/modules/helpers:177:18)
  at <PATH TO PROJECT>/node_modules/apigeelint/lib/package/myUtil.js:220:12
  at Object.<anonymous> (<PATH TO PROJECT>/node_modules/apigeelint/lib/package/myUtil.js:224:3)
  at Module._compile (node:internal/modules/cjs/loader:1364:14)
  at Module._extensions..js (node:internal/modules/cjs/loader:1422:10)
  at Module.load (node:internal/modules/cjs/loader:1203:32)
  at Module._load (node:internal/modules/cjs/loader:1019:12) {
    code: 'MODULE_NOT_FOUND',
    requireStack: [
      '<PATH TO PROJECT>/node_modules/apigeelint/lib/package/myUtil.js',
      '<PATH TO PROJECT>/node_modules/apigeelint/lib/package/Resource.js',
      '<PATH TO PROJECT>/node_modules/apigeelint/lib/package/Bundle.js',
      '<PATH TO PROJECT>/node_modules/apigeelint/lib/package/bundleLinter.js',
      '<PATH TO PROJECT>/node_modules/apigeelint/cli.js'
    ]
  }

Looking at the directory structure, it seems the @xmldom/xmldom library is not found under <PATH TO PROJECT>/node_modules/apigeelint/node_modules/@xmldom/xmldom/lib/dom.js, but under <PATH TO PROJECT>/node_modules/@xmldom/xmldom/lib/dom.js. I wouldn't be able to say if this could be related to yarn or not, to be honest.

Slightly tangential, I was looking through the patch in #474 to see if the original solution could help me find a way to solve our problem, and I noticed that the patch adds a getNodeModulesPathFor function, which is called with "@xmldom/xmldom" as its argument (here and here), but the function itself takes no argument and hardcodes the value of "@xmldom/xmldom"

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

4 participants