Węzeł.js Error: Cannot find module express

Napisałem swój pierwszy węzeł.aplikacja js, ale nie może znaleźć biblioteki express:

C:\ChatServer\Server>node server.js

module.js:340
    throw err;
          ^
Error: Cannot find module 'express'
    at Function.Module._resolveFilename (module.js:338:15)
    at Function.Module._load (module.js:280:25)
    at Module.require (module.js:364:17)
    at require (module.js:380:17)
    at Object.<anonymous> (C:\ChatServer\Server\server.js:6:9)
    at Object.<anonymous> (C:\ChatServer\Server\server.js:25:4)
    at Module._compile (module.js:456:26)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)

Ale express jest intalowany (z kluczem -g):

C:\ChatServer\Server>npm install -g express
npm http GET https://registry.npmjs.org/express
npm http 304 https://registry.npmjs.org/express
npm http GET https://registry.npmjs.org/connect/2.7.11
npm http GET https://registry.npmjs.org/commander/0.6.1
npm http GET https://registry.npmjs.org/range-parser/0.0.4
npm http GET https://registry.npmjs.org/mkdirp/0.3.4
npm http GET https://registry.npmjs.org/cookie/0.1.0
npm http GET https://registry.npmjs.org/buffer-crc32/0.2.1
npm http GET https://registry.npmjs.org/fresh/0.1.0
npm http GET https://registry.npmjs.org/methods/0.0.1
npm http GET https://registry.npmjs.org/send/0.1.0
npm http GET https://registry.npmjs.org/cookie-signature/1.0.1
npm http GET https://registry.npmjs.org/debug
npm http 304 https://registry.npmjs.org/mkdirp/0.3.4
npm http 304 https://registry.npmjs.org/range-parser/0.0.4
npm http 304 https://registry.npmjs.org/cookie/0.1.0
npm http 304 https://registry.npmjs.org/connect/2.7.11
npm http 304 https://registry.npmjs.org/commander/0.6.1
npm WARN package.json [email protected] No repository field.
npm http 304 https://registry.npmjs.org/buffer-crc32/0.2.1
npm http 304 https://registry.npmjs.org/fresh/0.1.0
npm http 304 https://registry.npmjs.org/methods/0.0.1
npm http 304 https://registry.npmjs.org/send/0.1.0
npm http 304 https://registry.npmjs.org/cookie-signature/1.0.1
npm WARN package.json [email protected] No repository field.
npm WARN package.json [email protected] No readme data.
npm WARN package.json [email protected] No repository field.
npm WARN package.json [email protected] No repository field.
npm WARN package.json [email protected] No repository field.
npm http 304 https://registry.npmjs.org/debug
npm http GET https://registry.npmjs.org/mime/1.2.6
npm http GET https://registry.npmjs.org/qs/0.6.5
npm http GET https://registry.npmjs.org/send/0.1.1
npm http GET https://registry.npmjs.org/formidable/1.0.14
npm http GET https://registry.npmjs.org/cookie/0.0.5
npm http GET https://registry.npmjs.org/bytes/0.2.0
npm http GET https://registry.npmjs.org/pause/0.0.1
npm http 304 https://registry.npmjs.org/mime/1.2.6
npm http 304 https://registry.npmjs.org/bytes/0.2.0
npm WARN package.json [email protected] No repository field.
npm http 304 https://registry.npmjs.org/pause/0.0.1
npm WARN package.json [email protected] No repository field.
npm http 304 https://registry.npmjs.org/formidable/1.0.14
npm http 304 https://registry.npmjs.org/qs/0.6.5
npm http 304 https://registry.npmjs.org/send/0.1.1
npm http 304 https://registry.npmjs.org/cookie/0.0.5
npm http GET https://registry.npmjs.org/mime
npm http 304 https://registry.npmjs.org/mime
C:\Users\Dmitry\AppData\Roaming\npm\express -> C:\Users\Dmitry\AppData\Roaming\npm\node_modules\express\bin\express
npm WARN package.json [email protected] 'repositories' (plural) Not supported.
npm WARN package.json Please pick one as the 'repository' field
npm WARN package.json [email protected] No repository field.
npm WARN package.json [email protected] No repository field.
[email protected] C:\Users\Dmitry\AppData\Roaming\npm\node_modules\express
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected] ([email protected])
└── [email protected] ([email protected], [email protected], [email protected], [email protected], [email protected], [email protected])

Niektóre informacje:

C:\ChatServer\Server>npm --version
1.2.24

C:\ChatServer\Server>node --version
v0.10.9

C:\ChatServer\Server>npm --version
1.2.24

C:\ChatServer\Server>npm ls -g installed express
npm WARN package.json [email protected] No repository field.
npm WARN package.json [email protected] No repository field.
npm WARN package.json [email protected] No repository field.
npm WARN package.json [email protected] No repository field.
npm WARN package.json [email protected] No repository field.
npm WARN package.json [email protected] 'repositories' (plural) Not supported.
npm WARN package.json Please pick one as the 'repository' field
npm WARN package.json [email protected] No repository field.
npm WARN package.json [email protected] No repository field.
npm WARN package.json [email protected] No repository field.
npm WARN package.json [email protected] No repository field.
C:\Users\Dmitry\AppData\Roaming\npm
└── [email protected]


C:\ChatServer\Server>npm ls installed express
C:\ChatServer\Server
└── (empty)
Jak mogę rozwiązać ten problem? (MUST I install it without -g?)
Author: DmitryR, 2013-06-18

13 answers

Musisz zainstalować Express lokalnie w kontekście swojej aplikacji (foldernode_modules):

$ npm install express

Powodem tego jest to, że aplikacje zawsze szukają zależności w swoim lokalnym kontekście. Instalacja globalna służy tylko do konfigurowania dostępnych w całym systemie plików binarnych, takich jak unit test runners lub bootstrappers lub tym podobne.

Z Express, gdy instalujesz go globalnie, otrzymujesz express binarny, który może uruchomić aplikację dla Ciebie. Więcej informacji, typ

$ express --help

Aby odpowiedzieć na twoje ostatnie pytanie: Tak , musisz zainstalować go bez -g.

 210
Author: Golo Roden,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2013-06-18 06:56:23

U mnie działało po zainstalowaniu expressa lokalnie z opcją --save w następujący sposób:

$ npm install express --save
 15
Author: Mustafamg,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2014-11-12 09:51:34

Sprawdź, czy nie instalujesz express modułu, użyj polecenia:

 npm install express

I jeśli twój katalog node_modules znajduje się w innym miejscu, Ustaw zmienną NODE_PATH envirnment:

 set NODE_PATH=your\directory\to\node_modules;%NODE_PATH%
 9
Author: Reza Ebrahimi,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2013-11-22 10:25:17

Golo dobrze wyjaśnili rozwiązanie, ale mogę dodać wyjaśnienie:
czasami Moduły node są instalowane w

/usr/local/lib/node_modules

I po uruchomieniu node blabla.Moduły js są wyszukiwane w

/lib

Więc rozwiązaniem jest utworzenie dowiązania symbolicznego:

sudo ln -s /usr/local/lib/node_modules/ /lib/node_modules
 5
Author: Luca Davanzo,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2015-11-18 08:11:52

W Twoim przypadku twój express moduł jest zainstalowany w C:\Users\Dmitry\AppData\Roaming\npm\node_modules\express, ale musisz umieścić ten moduł w katalogu twojego projektu. Dlatego powinieneś skopiować plik express foldery modułów z C:\Users\Dmitry\AppData\Roaming\npm\node_modules\ do katalogu projektu jako: C:\ChatServer\Server\node_modules. Jeśli nie masz folderu o nazwie "node_modules" w folderze projektu, utwórz go najpierw i wklej te pliki do tego folderu. Ta metoda działała dla mnie na moim komputerze z systemem windows. Uruchom ponownie serwer węzłów i ponownie uruchom polecenie node C:\ChatServer\Server>node server.js. Powinno zadziałać !!!!

 4
Author: Rahul Gupta,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2014-05-09 06:17:34

Na systemie operacyjnym opartym na Ubuntu możesz spróbować

sudo apt-get install node-express

Its working for me on Mint

 2
Author: Nickolay Savchenko,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2015-09-02 16:57:48

Utwórz jeden folder na dysku twardym np. sample1 i przejdź do wiersza polecenia type: cd i podaj ścieżkę do folderu sample1, a następnie zainstaluj wszystkie moduły...

Npm install express

Npm install jade

Npm install socket.io

A następnie cokolwiek tworzysz aplikację Zapisz w folderze sample1

Spróbuj...

 1
Author: Dev,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2014-02-20 11:38:09

Jeśli masz zainstalowany node w systemie, zainstaluj Express lokalnie dla swojego projektu, używając następującego polecenia Dla Windows:

npm install express

Lub

npm install express --save

Możesz dać mu globalny dostęp, używając:

npm install -g express --save
 1
Author: kg11,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2017-08-29 11:48:02
npm install; 

To działało dla mnie na Linuksie.

 0
Author: Roman Dimov,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2016-07-31 02:55:20

Mam ten sam problem. Miałem express zainstalowany globalnie w /usr / local / bin/. Kiedy robię 'npm install', express nie został utworzony w node_modules katalogu lokalnego.

  1. Sprawdź, czy masz nazwę pliku .npmrc w twoim $HOME
  2. jeśli ma 'global = true', zmień na 'global = false'
  3. teraz wykonaj 'npm install' w katalogu aplikacji. Bardziej prawdopodobne jest, że wszystkie moduły zależne od pakietu powinny być zainstalowane w node_modules (lokalnym) w katalogu aplikacji.
 0
Author: user2512153,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2016-11-03 23:55:50
  • sudo brew uninstall node
  • brew update
  • brew upgrade
  • brew cleanup
  • brew install node
  • sudo chown-r $(whoami) / usr / local
  • brew link --overwrite node
  • sudo brew postinstall node

To działało dla mnie na MacOS X Sierra

 0
Author: Durul Dalkanat,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2016-11-26 19:29:06

Przejdź do katalogu aplikacji i zainstaluj moduł express używając poniższego polecenia npm install express --save następnie wypisz moduł all install używając poniższego polecenia npm ls zobaczysz wszystkie lokalnie zainstalowane moduły.

 0
Author: Anayatullah Khan,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2017-01-07 19:56:19

Miałem ten błąd w vscode, chociaż Moduły gdzie są zainstalowane. Używam maszynopisu i ekspresu. W plikach server.ts wszystkie importowane elementy miały czerwone krzywe podkreślenia. Okazało się, że mam wadliwy plik tsconfig.json.

{
    "compileOnSave": false,
    "compilerOptions": {
        "module": "commonjs", // Previously this value was `es6`
        "target": "es6",
        "allowSyntheticDefaultImports": true,
        "baseUrl": "public",
        "sourceMap": true,
        "outDir": "dist",
        "jsx": "react",
        "strict": true,
        "preserveConstEnums": true,
        "removeComments": true,
        "noImplicitAny": true,
        "allowJs": true
    },
    "exclude": [
        "node_modules",
        "build"
    ]
}
 0
Author: Adrian Moisa,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2017-08-30 22:59:10