The required JS dependency "#silvia-odwyer/photon" is not available -- ClojureScript -- Node.js -- npm -- yarn - npm-install

I am doing the example project https://github.com/minimal-xyz/minimal-shadow-cljs-importing-npm to later add Photon dependency https://silvia-odwyer.github.io/photon/guide/using-photon-web/ and after following the steps I get this warning.
PS C:\Users\usuario\desktop\clojure\minimal-shadow-cljs-browser> yarn
shadow-cljs watch app
yarn run v1.22.10
$ C:\Users\usuario\desktop\clojure\minimal-shadow-cljs-browser\node_mo
dules\.bin\shadow-cljs watch app
shadow-cljs - config: C:\Users\usuario\desktop\clojure\minimal-shadow-
cljs-browser\shadow-cljs.edn
shadow-cljs - socket connect failed, server process dead?
shadow-cljs - HTTP server available at http://localhost:8080
shadow-cljs - server version: 2.11.5 running at http://localhost:9630
shadow-cljs - nREPL server started on port 49569
shadow-cljs - watching build :app
[:app] Configuring build.
[:app] Compiling ...
[:app] Build failure:
The required JS dependency "#silvia-odwyer/photon" is not available, i
t was required by "app/main.cljs".
Dependency Trace:
app/main.cljs
Searched for npm packages in:
C:\Users\usuario\desktop\clojure\minimal-shadow-cljs-browser\n
ode_modules
See: https://shadow-cljs.github.io/docs/UsersGuide.html#npm-install
Before execute 'npx shadow-cljs watch client' or 'yarn shadow-cljs watch client' I tried with:
npm install --save #silvia-odwyer/photon
npm install #silvia-odwyer/photon
yarn add #silvia-odwyer/photon
and the files are in node_modules folder indeed, but it doesn't work
I tried 'npm cache clean -f' and installing again
I tried deleting node_modules folder and package-lock.jason file and installing again
The same issue with https://github.com/minimal-xyz/minimal-shadow-cljs-browser
The example projects work fine with the included dependencies (before installing Photon dependency)
Here is my package.json after installing:
{
"scripts": {
"html": "mkdir -p target/; cp entry/index.html target/"
},
"dependencies": {
"#silvia-odwyer/photon": "^0.2.0",
"dayjs": "^1.7.7",
"lodash": "^4.17.19",
"shortid": "^2.2.13"
},
"devDependencies": {
"shadow-cljs": "^2.6.23"
},
"name": "minimal-shadow-cljs-importing-npm",
"description": "",
"version": "0.1.0",
"main": "index.js",
"author": "",
"license": "MIT"
}
Here is my shadow-cljs.edn:
{:source-paths ["src"]
:builds {:client {:output-dir "target/"
:asset-path "./"
:target :browser
:modules {:client {:init-fn app.main/main!}}
:devtools {:after-load app.main/reload!
:http-root "target"
:http-port 8080}}}
:jvm-opts ["-Xmx1024m"]}
And heres is the main.cljs file requiring/importing the dependency the same as the others:
(ns app.main
(:require ["dayjs" :as dayjs]
["shortid" :as shortid]
["lodash" :as lodash]
["lodash" :refer [isString]]
["#silvia-odwyer/photon" :as sop]))
PS C:\Users\usuario\desktop\clojure\minimal-shadow-cljs-browser> node -v
v12.19.0
PS C:\Users\usuario\desktop\clojure\minimal-shadow-cljs-browser> npm -v
6.14.8
I'm missing something?

Photon is a high-performance image processing library, written in Rust and compilable to WebAssembly, which can be used both natively and on the web.
shadow-cljs does not support WebAssembly bundling at this point.
Not sure why you are getting an error telling you that it doesn't exist. The library in question contains a compiled .wasm file and as such won't work properly anyways though.

Related

Dependency miss match error is throwing while npm install if I use `jsonpscriptsrc-webpack-plugin` npm package with gulp 4.0.2

If we try to npm install the jsonpscriptsrc-webpack-plugin npm package along with gulp 4.0.2 to override the jsonpScriptSrc method, we are facing the dependency mismatch issue.
This issue is occurring only if we use the node version 15.0.0 to 15.7.0 and having gulp 4.0.2 in dependency list. For other node versions, it installs the package fine.
package json details
Issue details:
Error details
Replication procedure:
Create a package.json file and copy & paste the below code.
{
"name": "wepack",
"version": "1.1.0",
"license": "SEE LICENSE IN license",
"devDependencies": {
"gulp": "^4.0.2",
"jsonpscriptsrc-webpack-plugin": "^1.0.0"
}
}
Switch the node js version to 15.7.0
Try to npm install inside the package.json file location and you will find the mentioned issue.

Can "NPM -i" (local) install a global package without i know it?

I'm ok with local dependencies that packages install. But now I have a huge concerns about if a local installed package can install other global packages as dependencies.
as example:
npm install nunjucks
npm install sqlite
or
npm install botkit
It is not possible to mark a dependency as global in package.json, so that it is installed system-wide when you run npm i.
Here's an old comment by Isaac Schlueter stating that this will never be implemented.
Hooowever, it would be really simple to write a preinstall script to install arbitary dependencies globally.
{
"name": "Project",
"version": "1.0.0",
"description": "Preinstall script to install global deps",
"main": "index.js",
"scripts": {
"preinstall": "node -e \"const {execSync} = require('child_process'); JSON.parse(fs.readFileSync('package.json')).globalDependencies.forEach(globalDep => execSync('npm i -g ' + globalDep));\""
},
"dependencies": {
"react": "16.13.1"
},
"globalDependencies": [
"lodash"
],
"license": "ISC"
}
Copy this code into a package.json file in a folder on your PC. Then, in the folder run npm i. It will install React locally (in a node_modules folder) and it will install lodash globally.
You can verify this using: npm i ls -g --depth=0.
Reference: Install dependencies globally and locally using package.json
As to your question:
Can npm -i (local) install a global package without me knowing it?
It's not entirely silent. When running npm i for the above package.json file, you would see the following output:
> Project#1.0.0 preinstall /home/jim/Desktop/Project
> node -e "const {execSync} = require('child_process'); JSON.parse(fs.readFileSync('package.json')).globalDependencies.forEach(globalDep => execSync('npm i -g ' + globalDep));"
npm WARN Project#1.0.0 No repository field.
audited 6 packages in 1.113s
found 0 vulnerabilities
But whether you would catch this when running npm i on a large project is debatable.

How to install local NPM module and it's dependencies to project?

I'm working on shareable eslint configuration to spread automation and internal best-practices. So I'm adding some eslint plugins and tools as dependencies.
Context
Env
$ node --version;
v8.2.1
$ npm --version
5.3.0
Local package
To do so I created a local npm project, says eslint-config-company, with the following package.json:
{
"name": "eslint-config-company",
"version": "0.0.1",
"main": "index.js",
"dependencies": {
"eslint": "4.x.x",
"eslint-plugin-ember-suave": "1.x.x",
"eslint-plugin-prettier": "2.x.x",
"prettier": "1.x.x"
},
"files": [
"index.js"
],
"keywords": [
"eslint",
"eslintconfig"
],
"repository": "company/eslint-config-company",
"private": true
}
and files:
index.js package.json README.md yarn.lock
Installing
Then, I install my eslint-config-company package into a another project to test it:
npm install --save-dev --verbose ../eslint-config-company
In node_modules/ directory I got the eslint-config-company/ as a symlink:
$ ls node_modules/eslint-config-company -lah
lrwxrwxrwx 1 me me 29 Aug 17 22:02 node_modules/eslint-config-company -> ../../eslint-config-company/
but no trace of either prettier nor eslint-plugin-prettier
$ ls node_modules/{prettier,eslint-plugin-prettier}
ls: cannot access 'node_modules/prettier': No such file or directory
ls: cannot access 'node_modules/eslint-plugin-prettier': No such file or directory
N.B.: eslint and eslint-plugin-ember-suave are already dependencies of that project thus exists.
Question
Am I wrong assuming that my package's dependencies will install on npm install ?
How do I fix my package in order to install them?
related: issue on npm/npm
The eslint-config-company's dependencies are held in that module's node_modules folder - so it will be able to find the code it needs via the symlink (assuming npm install has been run on the eslint-config-company module folder).
When packaged up - the node_module folder is included as well, so it translates up to delivery time as well.
Create global module of your project eslint-config-company (in this module folder):
npm link
and links the global installation target in another project whit :
npm link eslint-config-company
source : https://docs.npmjs.com/cli/link

npm install dependencies of local modules

I'm having trouble using npm with a local module. My project's structure looks like:
package.json
local_module/
- package.json
- gulpfile.json
gulpfile.js
The main project's package.json is essentially:
{
"dependencies": {
"local_module": "file:local_module"
},
"devDependencies": {
"gulp": "..."
}
}
The local module's package.json is essentially:
{
"scripts": {
"prepublish": "gulp release"
},
"devDependencies": {
"gulp": "..."
}
}
My intention is keep my project modular by keeping local_module as its own package that is used as a dependency for the main project. I want to run npm install in the main project and use local_module from node_modules. However, local_module needs gulp installed to run the prepublish step, and when running npm install from the main project, it does not install the dependencies for local_module, and so gulp isn't installed, so it can't do the prepublish step.
Several questions like this have been asked, like NPM doesn't install module dependencies, but many are old and there are so many versions of npm that I can't get a clear solution.
How can I get npm to install local_module's dependencies before the prepublish step? I tried adding a preinstall step for the main project, e.g.
"preinstall": "cd local_module && npm install"
But it seems npm tries to run the prepublish step of local_module before running the preinstall for the main project. I want a solution that will do this in one npm install step rather than having a separate step before this to do npm install in the local module.
I have found a solution that will work for me in the immediate future. I changed local_module's package.json to:
{
"scripts": {
"prepublish": "npm install --ignore-scripts && gulp release"
},
"devDependencies": {
"gulp": "..."
}
}
When npm install is run from the main project, the prepublish step is run first in local_module, so I force prepublish to also do an install so that gulp is available to do the actual prepublish step. This is hardly ideal however.

How can I use npm 2.0 on IBM Bluemix?

Is it possible to use npm version 2 on Bluemix? By default it runs version 1.4, but I want to "install" a package from a local directory.
I was able to configure the npm version when using the community open source Node.js buildpack and setting the npm version in my package.json. See below.
"engines": {
"npm": "^2.1.0"
}
cf push mynodeapp -b https://github.com/cloudfoundry/nodejs-buildpack
Not sure if this is possible using the default Node.js buildpack yet.
In the staging output, you should see:
Npm engine: ^2.1.0
Probably you have to modify package.json like below:
"engines": {
"npm": "^2.1.0"
}
After that you can push your app to bluemix and verify the same in staging output.
Hope it helps!!
You could package the dependency inside your application directory, and create a "preinstall" script that will run an npm install on that dependency:
"scripts": {
"start": "node server.js",
"preinstall": "npm install relative/path/to/module"
},
This should work locally and on Bluemix. Note that "postinstall" is also an option.