如何在macOS上在现有项目文件夹中安装和运行shadow cljs



我正在尝试在MacOS Monterey 12.5中安装shadow cljs。我是Apple生态系统、npm和ClojureScript堆栈的新手。这对我来说是一个新的世界。

这是项目文件夹,正如您所看到的,已经有一个package.json文件:

pedro@Pedros-MacBook-Air balance % ls -l1
LICENSE
README.md
config
dev.cljs.edn
docs
externs
firebase-deploy.my-instance-specific-variables.TEMPLATE.edn
firestore.rules.json
makefile
package-lock.json
package.json
project.clj
public
semantic
semantic.json
shadow-cljs.edn
src
tools

这是package.json文件的内容:

pedro@Pedros-MacBook-Air balance % cat package.json 
{
"name": "xxxx",
"version": "0.3.0",
"description": "xxxx",
"repository": {
"type": "git",
"url": "xxxxxxxxxxxxx.com"
},
"author": {
"name": "xxxxxxxxx",
"email": "xxxxxxx"
},
"license": "unlicensed",
"scripts": {
"dev": "shadow-cljs watch app;",
"release": "shadow-cljs release app;",
"server": "shadow-cljs server;",
"clean": "rm -rf target; rm -rf public/js"
},
"dependencies": {
"@firebase/app": "^0.4.22",
"@firebase/auth": "^0.11.8",
"@firebase/database": "^0.4.12",
"@firebase/firestore": "^1.6.4",
"@firebase/logger": "^0.1.28",
"@firebase/webchannel-wrapper": "^0.2.29",
"@js-joda/core": "3.2.0",
"@js-joda/locale_en-us": "3.1.1",
"@js-joda/timezone": "2.2.0",
"@sheet/core": "^1.20191114.1",
"create-react-class": "^15.6.3",
"firebase": "5.7.3",
"highlight.js": "^9.16.2",
"process": "^0.11.10",
"react": "^16.11.0",
"react-dom": "^16.11.0",
"react-flip-move": "^3.0.4",
"react-highlight.js": "^1.0.7",
"reactstrap": "^8.6.0",
"semantic-ui": "^2.4.2",
"semantic-ui-react": "^0.82.5",
"smartystreets-javascript-sdk": "^1.9.2",
"stripe": "^8.158.0",
"tslib": "1.10.0"
},
"devDependencies": {
"shadow-cljs": "2.15.3"
}
}

手册显示:

如果您已经有了一个package.json,并且只想添加shadow cljs运行NPM

$npm安装--保存dev-shaped-cljs

因此,我做到了:

pedro@Pedros-MacBook-Air balance % npm install --save-dev shadow-cljs

检索到以下错误:

npm ERR! code ERESOLVE
npm ERR! ERESOLVE could not resolve
npm ERR! 
npm ERR! While resolving: @js-joda/timezone@2.2.0
npm ERR! Found: @js-joda/core@3.2.0
npm ERR! node_modules/@js-joda/core
npm ERR!   peer @js-joda/core@">=1.11.0" from @js-joda/locale_en-us@3.1.1
npm ERR!   node_modules/@js-joda/locale_en-us
npm ERR!     @js-joda/locale_en-us@"3.1.1" from the root project
npm ERR!   @js-joda/core@"3.2.0" from the root project
npm ERR! 
npm ERR! Could not resolve dependency:
npm ERR! peer @js-joda/core@"^1.11.0" from @js-joda/timezone@2.2.0
npm ERR! node_modules/@js-joda/timezone
npm ERR!   peer @js-joda/timezone@"^2.2.0" from @js-joda/locale_en-us@3.1.1
npm ERR!   node_modules/@js-joda/locale_en-us
npm ERR!     @js-joda/locale_en-us@"3.1.1" from the root project
npm ERR!   @js-joda/timezone@"2.2.0" from the root project
npm ERR! 
npm ERR! Conflicting peer dependency: @js-joda/core@1.12.0
npm ERR! node_modules/@js-joda/core
npm ERR!   peer @js-joda/core@"^1.11.0" from @js-joda/timezone@2.2.0
npm ERR!   node_modules/@js-joda/timezone
npm ERR!     peer @js-joda/timezone@"^2.2.0" from @js-joda/locale_en-us@3.1.1
npm ERR!     node_modules/@js-joda/locale_en-us
npm ERR!       @js-joda/locale_en-us@"3.1.1" from the root project
npm ERR!     @js-joda/timezone@"2.2.0" from the root project
npm ERR! 
npm ERR! Fix the upstream dependency conflict, or retry
npm ERR! this command with --force, or --legacy-peer-deps
npm ERR! to accept an incorrect (and potentially broken) dependency resolution.
npm ERR! 
npm ERR! See /Users/pedro/.npm/eresolve-report.txt for a full report.
npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/pedro/.npm/_logs/2022-08-01T14_36_59_868Z-debug-0.log

在阅读了关于上游依赖冲突的堆栈溢出的其他问题后,我尝试了,但没有成功以下内容:

pedro@Pedros-MacBook-Air balance % npm install --legacy-peer-deps --save-dev shadow-cljs

它在querystring旧版上返回了一条不同的错误消息

pedro@Pedros-MacBook-Air balance % npm install --legacy-peer-deps --save-dev shadow-cljs
npm WARN deprecated querystring@0.2.0: The querystring API is considered Legacy. new code should use the URLSearchParams API instead.
npm ERR! code 1
npm ERR! path /Users/pedro/projects/balance/node_modules/semantic-ui
npm ERR! command failed
npm ERR! command sh /var/folders/fh/7d_1drwd2ps3zw03j9ftkqs80000gn/T/install-64525ec5.sh
npm ERR! fs.js:47
npm ERR! } = primordials;
npm ERR!     ^
npm ERR! 
npm ERR! ReferenceError: primordials is not defined
npm ERR!     at fs.js:47:5
npm ERR!     at req_ (/Users/pedro/projects/balance/node_modules/natives/index.js:143:24)
npm ERR!     at Object.req [as require] (/Users/pedro/projects/balance/node_modules/natives/index.js:55:10)
npm ERR!     at Object.<anonymous> (/Users/pedro/projects/balance/node_modules/graceful-fs/fs.js:1:37)
npm ERR!     at Module._compile (node:internal/modules/cjs/loader:1120:14)
npm ERR!     at Module._extensions..js (node:internal/modules/cjs/loader:1174:10)
npm ERR!     at Module.load (node:internal/modules/cjs/loader:998:32)
npm ERR!     at Module._load (node:internal/modules/cjs/loader:839:12)
npm ERR!     at Module.require (node:internal/modules/cjs/loader:1022:19)
npm ERR!     at require (node:internal/modules/cjs/helpers:102:18)
npm ERR! 
npm ERR! Node.js v18.7.0
npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/pedro/.npm/_logs/2022-08-01T14_45_00_773Z-debug-0.log

我还尝试了另一个建议:

pedro@Pedros-MacBook-Air balance % npm list --depth=3  

检索到的:

tallyfor-balance@0.3.0 /Users/pedro/projects/balance
├── UNMET DEPENDENCY @firebase/app@^0.4.22
├── UNMET DEPENDENCY @firebase/auth@^0.11.8
├── UNMET DEPENDENCY @firebase/database@^0.4.12
├── UNMET DEPENDENCY @firebase/firestore@^1.6.4
├── UNMET DEPENDENCY @firebase/logger@^0.1.28
├── UNMET DEPENDENCY @firebase/webchannel-wrapper@^0.2.29
├── UNMET DEPENDENCY @js-joda/core@3.2.0
├── UNMET DEPENDENCY @js-joda/locale_en-us@3.1.1
├── UNMET DEPENDENCY @js-joda/timezone@2.2.0
├── UNMET DEPENDENCY @sheet/core@^1.20191114.1
├── UNMET DEPENDENCY create-react-class@^15.6.3
├── UNMET DEPENDENCY firebase@5.7.3
├── UNMET DEPENDENCY highlight.js@^9.16.2
├── UNMET DEPENDENCY process@^0.11.10
├── UNMET DEPENDENCY react-dom@^16.11.0
├── UNMET DEPENDENCY react-flip-move@^3.0.4
├── UNMET DEPENDENCY react-highlight.js@^1.0.7
├── UNMET DEPENDENCY react@^16.11.0
├── UNMET DEPENDENCY reactstrap@^8.6.0
├── UNMET DEPENDENCY semantic-ui-react@^0.82.5
├── UNMET DEPENDENCY semantic-ui@^2.4.2
├── UNMET DEPENDENCY shadow-cljs@2.15.3
├── UNMET DEPENDENCY smartystreets-javascript-sdk@^1.9.2
├── UNMET DEPENDENCY stripe@^8.158.0
└── UNMET DEPENDENCY tslib@1.10.0
npm ERR! code ELSPROBLEMS
npm ERR! missing: @firebase/app@^0.4.22, required by tallyfor-balance@0.3.0
npm ERR! missing: @firebase/auth@^0.11.8, required by tallyfor-balance@0.3.0
npm ERR! missing: @firebase/database@^0.4.12, required by tallyfor-balance@0.3.0
npm ERR! missing: @firebase/firestore@^1.6.4, required by tallyfor-balance@0.3.0
npm ERR! missing: @firebase/logger@^0.1.28, required by tallyfor-balance@0.3.0
npm ERR! missing: @firebase/webchannel-wrapper@^0.2.29, required by tallyfor-balance@0.3.0
npm ERR! missing: @js-joda/core@3.2.0, required by tallyfor-balance@0.3.0
npm ERR! missing: @js-joda/locale_en-us@3.1.1, required by tallyfor-balance@0.3.0
npm ERR! missing: @js-joda/timezone@2.2.0, required by tallyfor-balance@0.3.0
npm ERR! missing: @sheet/core@^1.20191114.1, required by tallyfor-balance@0.3.0
npm ERR! missing: create-react-class@^15.6.3, required by tallyfor-balance@0.3.0
npm ERR! missing: firebase@5.7.3, required by tallyfor-balance@0.3.0
npm ERR! missing: highlight.js@^9.16.2, required by tallyfor-balance@0.3.0
npm ERR! missing: process@^0.11.10, required by tallyfor-balance@0.3.0
npm ERR! missing: react-dom@^16.11.0, required by tallyfor-balance@0.3.0
npm ERR! missing: react-flip-move@^3.0.4, required by tallyfor-balance@0.3.0
npm ERR! missing: react-highlight.js@^1.0.7, required by tallyfor-balance@0.3.0
npm ERR! missing: react@^16.11.0, required by tallyfor-balance@0.3.0
npm ERR! missing: reactstrap@^8.6.0, required by tallyfor-balance@0.3.0
npm ERR! missing: semantic-ui-react@^0.82.5, required by tallyfor-balance@0.3.0
npm ERR! missing: semantic-ui@^2.4.2, required by tallyfor-balance@0.3.0
npm ERR! missing: shadow-cljs@2.15.3, required by tallyfor-balance@0.3.0
npm ERR! missing: smartystreets-javascript-sdk@^1.9.2, required by tallyfor-balance@0.3.0
npm ERR! missing: stripe@^8.158.0, required by tallyfor-balance@0.3.0
npm ERR! missing: tslib@1.10.0, required by tallyfor-balance@0.3.0
npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/pedro/.npm/_logs/2022-08-01T14_44_49_026Z-debug-0.log
pedro@Pedros-MacBook-Air balance % npm install --legacy-peer-deps --save-dev shadow-cljs
npm WARN deprecated querystring@0.2.0: The querystring API is considered Legacy. new code should use the URLSearchParams API instead.
npm ERR! code 1
npm ERR! path /Users/pedro/projects/balance/node_modules/semantic-ui
npm ERR! command failed
npm ERR! command sh /var/folders/fh/7d_1drwd2ps3zw03j9ftkqs80000gn/T/install-64525ec5.sh
npm ERR! fs.js:47
npm ERR! } = primordials;
npm ERR!     ^
npm ERR! 
npm ERR! ReferenceError: primordials is not defined
npm ERR!     at fs.js:47:5
npm ERR!     at req_ (/Users/pedro/projects/balance/node_modules/natives/index.js:143:24)
npm ERR!     at Object.req [as require] (/Users/pedro/projects/balance/node_modules/natives/index.js:55:10)
npm ERR!     at Object.<anonymous> (/Users/pedro/projects/balance/node_modules/graceful-fs/fs.js:1:37)
npm ERR!     at Module._compile (node:internal/modules/cjs/loader:1120:14)
npm ERR!     at Module._extensions..js (node:internal/modules/cjs/loader:1174:10)
npm ERR!     at Module.load (node:internal/modules/cjs/loader:998:32)
npm ERR!     at Module._load (node:internal/modules/cjs/loader:839:12)
npm ERR!     at Module.require (node:internal/modules/cjs/loader:1022:19)
npm ERR!     at require (node:internal/modules/cjs/helpers:102:18)
npm ERR! 
npm ERR! Node.js v18.7.0
npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/pedro/.npm/_logs/2022-08-01T14_45_00_773Z-debug-0.log

使用全局标志也没有解决:

pedro@Pedros-MacBook-Air balance % npm install -g npm                                   

changed 14 packages, and audited 202 packages in 1s
11 packages are looking for funding
run `npm fund` for details

我不确定还能尝试什么。

有什么建议吗?我错过什么了吗?

观察我能够成功地在shadow-cljsrepo的GitHub README上运行快速启动示例。

Last login: Mon Aug 1 16:40:55 on ttys000
pedro@Pedros-MacBook-Air ~ % cd projects 
pedro@Pedros-MacBook-Air projects % cd acme-app 
pedro@Pedros-MacBook-Air acme-app % npx shadow-cljs node-repl
shadow-cljs - config: /Users/pedro/projects/acme-app/shadow-cljs.edn
shadow-cljs - server version: 2.19.8 running at http://localhost:9630
shadow-cljs - nREPL server started on port 50748
cljs.user=> shadow-cljs - #4 ready!
(+ 99 1)
100

谢谢。

当您有这样的现有项目时,您只需运行npm install,不需要任何其他参数,即可安装package.json中列出的所有依赖项。npm ci也可以,这是一种干净安装,如果你有一个现有的package-lock.json,它将确保安装以前使用的确切版本。

但是,您的项目似乎有点过时,这意味着您使用的npm版本可能比创建项目时使用的版本更新。这就是为什么您可能需要运行npm install --legacy-peer-deps

当您执行npm install shadow-cljs(或您尝试的任何其他变体(时,它会告诉npm只安装shadow-cljs而忽略其余部分,这解释了所有未满足的依赖关系。

最新更新