2017-01-10 151 views
0

我試圖啓動一個需要node.js的新項目。創建文件夾後,我試圖讓node_modules顯示在我的項目文件夾中。因此,我用在npm init之後package.json文件沒有依賴關係

npm init 

,然後,我用

npm install 

的安裝後,我意識到,我的node_modules文件夾爲空,所以我檢查了package.json。我意識到,沒有依賴關係

有沒有什麼辦法可以解決這個問題?

+0

NPM安裝package_you_need --save-dev的。請參閱[doco](https://docs.npmjs.com/cli/install) – lloyd

+0

您尚未安裝任何軟件包,請嘗試npm install express --save,您將在node_modules中看到express –

回答

1

當你做NPM初始化你可能輸入的數值如下面的CLI中:

name: (testApp) 
Sorry, name can no longer contain capital letters. 
name: (testApp) testApp 
Sorry, name can no longer contain capital letters. 
name: (testApp) test-app 
version: (1.0.0) 
description: This is a test app 
entry point: (index.js) app.js 
test command: npm test 
git repository: 
keywords: 
author: Sagar Gopale 
license: (ISC) 
About to write to /home/sagargopale/Projects/testApp/package.json: 

;那麼,的package.json創建了上面的配置如下:

{ 
    "name": "test-app", 
    "version": "1.0.0", 
    "description": "This is a test app", 
    "main": "app.js", 
    "scripts": { 
    "test": "npm test" 
    }, 
    "author": "Sagar Gopale", 
    "license": "ISC" 
} 

當你會安裝任何依賴項,它會在package.json中添加依賴項塊。例如,如果我這樣做

npm install express --save 

那麼的package.json看起來象下面這樣:

{ 
    "name": "test-app", 
    "version": "1.0.0", 
    "description": "This is a test app", 
    "main": "app.js", 
    "scripts": { 
    "test": "npm test" 
    }, 
    "author": "Sagar Gopale", 
    "license": "ISC", 
    "dependencies": { 
    "express": "^4.14.0" 
    } 
} 
相關問題