wooorm / load-plugin Goto Github PK
View Code? Open in Web Editor NEWLoad a submodule / plugin
License: MIT License
Load a submodule / plugin
License: MIT License
Hi. You rely on npm-prefix
package for detecting npm prefix.
But this package is very outdated I suppose.
At least it may give wrong results on windows.
By default nodejs with npm are installing into 'system' folder:
C:\Program Files\nodejs\node.exe
C:\Program Files\nodejs\npm.cmd
C:\Program Files\nodejs\node_modules\npm\...
In this situation the npm-prefix
package correctly returns C:\Program Files\nodejs
.
But... all consequent global installs go to user's folder (without requirements of privileged access to system folders):
C:\Users\{username}\AppData\Roaming\npm\node_modules\...
npm i -g npm
becomes C:\Users\{username}\AppData\Roaming\npm\node_modules\npm\...
npm i -g remark-cli
becomes C:\Users\{username}\AppData\Roaming\npm\node_modules\remark-cli\...
npm i -g remark-html
becomes C:\Users\{username}\AppData\Roaming\npm\node_modules\remark-html\...
And here arises the problem with npm-prefix
.
It still returns C:\Program Files\nodejs
but not the actual C:\Users\{username}\AppData\Roaming\npm
.
Eventually your load-plugin
searches for modules in a wrong directory.
So I suggest you to find another solution.
Some other package or maybe just npm config get prefix
?
Thank you.
I believe the issue described here (remarkjs/remark-language-server#6 (comment)) is a result of an assumption that packages are stored in a node_modules
directory.
I tried running resolvePlugin
and loadPlugin
against my project and got the following error
% yarn node test.mjs
Error: Cannot find package 'lint' imported from /<mycwd>/
at new NodeError (file:///<mycwd>/.yarn/cache/import-meta-resolve-npm-2.1.0-fcf1208127-4554ea5e2d.zip/node_modules/import-meta-resolve/lib/errors.js:276:5)
at packageResolve (file:///<mycwd>/.yarn/cache/import-meta-resolve-npm-2.1.0-fcf1208127-4554ea5e2d.zip/node_modules/import-meta-resolve/lib/resolve.js:1060:9)
at moduleResolve (file:///<mycwd>/.yarn/cache/import-meta-resolve-npm-2.1.0-fcf1208127-4554ea5e2d.zip/node_modules/import-meta-resolve/lib/resolve.js:1117:20)
at defaultResolve (file:///<mycwd>/.yarn/cache/import-meta-resolve-npm-2.1.0-fcf1208127-4554ea5e2d.zip/node_modules/import-meta-resolve/lib/resolve.js:1266:15)
at resolve (file:///<mycwd>/.yarn/cache/import-meta-resolve-npm-2.1.0-fcf1208127-4554ea5e2d.zip/node_modules/import-meta-resolve/index.js:29:12)
at attempt (file:///<mycwd>/.yarn/cache/load-plugin-npm-5.1.0-5695bc6a89-d450c9a083.zip/node_modules/load-plugin/index.js:167:15)
at resolvePlugin (file:///<mycwd>/.yarn/cache/load-plugin-npm-5.1.0-5695bc6a89-d450c9a083.zip/node_modules/load-plugin/index.js:148:16)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
at async file:///<mycwd>/test.mjs:5:17 {
code: 'ERR_MODULE_NOT_FOUND'
}
where test.mjs
is
import { loadPlugin, resolvePlugin } from 'load-plugin';
(async () => {
try {
console.log(await resolvePlugin('lint', { prefix: 'remark' }));
} catch (error) {
console.error(error);
}
})();
resolvePlugin
tries to resolve a plugin from several locations. Each try may fail, but only the last error is preserved. I think itβs better to collect all errors, and throw an AggregateError
instead. This communicates all attempted locations to the user.
If only one error is thrown, perhaps no AggregateError
is needed.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. πππ
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google β€οΈ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.