如果我删除 package.json 中的依赖项,是否可以运行命令让 NPM 从 node_modules 目录中删除它?
我知道我可以直接从 NPM 中删除它
npm uninstall <module> --save
Run Code Online (Sandbox Code Playgroud)
但我认为,如果我可以从 package.json 中删除该行并运行命令,然后 NPM 会删除它(和/或安装我添加到 package.json 中的任何内容),那么会更容易。换句话说,我想要一个命令来使我的 node_modules 目录反映我在 package.json 中设置的依赖项。
有什么办法可以做到这一点吗?
有什么方法可以为我的 python 文件夹创建 package.json 文件,就像在 NodeJS (npm) 中一样?
例如:如果我使用 pip 导入 Flask,我希望 Flask 出现在 package.json 文件中。它不必是 JSON,也可以是 .txt 文件。
仅供参考:我想要该文件,以便我可以在传输文件或将文件夹上传到 GitHub 时立即安装所有依赖项
谢谢!
尝试从package.json
. 此方法仅运行server1.js
,但忽略server2.js
包.json
{
"name": "demo",
"version": "1.0.0",
"description": "demo",
"main": "server1.js",
"dependencies": {
"express": "^4.14.0",
"socket.io": "^1.5.1"
},
"devDependencies": {},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "node server1.js && node server2.js",
}
}
Run Code Online (Sandbox Code Playgroud)
PS——代码将在AWS中使用
我愚蠢地使用了命令 npmauditfix --force 而不备份软件包,现在我在我的反应应用程序中发现了一些错误。
每当我启动应用程序时,我都会收到错误:
./src/reportWebVitals.js 中的错误语法错误:“导入”和“导出”可能仅出现在顶层
我该如何解决这个问题?
我的 reportWebVitals.js 文件如下所示:
const reportWebVitals = onPerfEntry => {
if (onPerfEntry && onPerfEntry instanceof Function) {
import('web-vitals').then(({ getCLS, getFID, getFCP, getLCP, getTTFB }) => {
getCLS(onPerfEntry);
getFID(onPerfEntry);
getFCP(onPerfEntry);
getLCP(onPerfEntry);
getTTFB(onPerfEntry);
});
}
};
export default reportWebVitals;
Run Code Online (Sandbox Code Playgroud)
我的 package.json 如下所示:
{
"name": "duran_supplements_and_workout_equipment",
"version": "0.1.0",
"private": true,
"proxy": "http://localhost:8000",
"dependencies": {
"@testing-library/jest-dom": "^5.11.4",
"@testing-library/react": "^11.1.0",
"@testing-library/user-event": "^12.1.10",
"http-proxy-middleware": "^2.0.1",
"mongoose": "^5.12.13",
"react": "^17.0.2",
"react-dom": "^17.0.2",
"react-scripts": "^0.9.5",
"socket.io-client": "^4.1.2",
"web-vitals": "^1.0.1"
},
"scripts": …
Run Code Online (Sandbox Code Playgroud) 我在使用 angular 14 的 package.json 安装 ngx-bootstrap 时遇到问题,如下所示:
{
"name": "testproj",
"version": "0.0.0",
"scripts": {
"ng": "ng",
"start": "ng serve",
"build": "ng build",
"watch": "ng build --watch --configuration development",
"test": "ng test"
},
"private": true,
"dependencies": {
"@angular/animations": "^14.0.0",
"@angular/common": "^14.0.0",
"@angular/compiler": "^14.0.0",
"@angular/core": "^14.0.0",
"@angular/forms": "^14.0.0",
"@angular/platform-browser": "^14.0.0",
"@angular/platform-browser-dynamic": "^14.0.0",
"@angular/router": "^14.0.0",
"rxjs": "~7.5.0",
"tslib": "^2.3.0",
"zone.js": "~0.11.4"
},
"devDependencies": {
"@angular-devkit/build-angular": "^14.0.3",
"@angular/cli": "~14.0.3",
"@angular/compiler-cli": "^14.0.0",
"@types/jasmine": "~4.0.0",
"jasmine-core": "~4.1.0",
"karma": "~6.3.0",
"karma-chrome-launcher": "~3.1.0",
"karma-coverage": "~2.2.0",
"karma-jasmine": "~5.0.0", …
Run Code Online (Sandbox Code Playgroud) 我希望能够通过修改 的值在任何 URL 上运行我的 Cypress 脚本,baseUrl
但该命令不会更改它。
"cypress open --env version=development --config baseUrl=https://google.com"
Run Code Online (Sandbox Code Playgroud)
我也尝试过 env 变量,但这也不起作用:
"cypress:open:dev": "cypress open --env version=development,baseUrl=https://google.com"
Run Code Online (Sandbox Code Playgroud)
配置文件:
export default defineConfig({
e2e: {
async setupNodeEvents(on, config) {
const version = config.env.version || 'development'
const configFile = await import(path.join(
config.projectRoot,
'cypress/config',
`${version}.json`
));
const credentialsFile = await import(path.join(
config.projectRoot,
'cypress/config',
'credentials.json'
));
config = {
...config, // take config defined in this file
...configFile // merge/override from the external file
}
config.env = {
...config.env, // …
Run Code Online (Sandbox Code Playgroud) package.json ×6
node.js ×3
module ×2
npm ×2
angular ×1
cypress ×1
import ×1
javascript ×1
python ×1
socket.io ×1