Поиск по этому блогу

четверг, 30 июня 2016 г.

Разобрался с деревом node_modules в NPM (Nodejs), а ошибку обещают исправить разработчики

Ошибка Requiring external module babel-core/register подоспела вовремя. Иначе так и не прочитал бы документацию npm. Здесь фрагменты из документации и мои упражнения с опциями CLI npm.
Однако, оказалось, что мои настойчивые поиски дали сомнительный результат только после того, как я догадался ограничить поиск (в Гугле)только последним месяцем. Сразу же нашелся призыв разработчиков подождать следующего релиза.
Но верится с трудом. Такие ошибки у них вываливались регулярно в течение последнего года... Чего-то я не понимаю...

style="float:left; margin-right:10px;"How to list npm user-installed packages?
Running "npm list -g --depth=0" returns extraneous err and missing files? #10004
npm-config More than you probably want to know about npm configuration
npm windows install globally - results in -npm ERR! extraneous… npm ERR! extraneous means a package is installed but is not listed in your project's package.json. Since you're listing packages that have been installed globally, it's going to give you a lot of extraneous errors that can be simply ignored because most things installed globally will not be in your project's package.json.
Shorthands and Other CLI Niceties

Пытался решить вот эту задачу, но оказалось, что решения нет (поиск за последний месяц)

In [ ]:
F:\stradorusite\MDL\material-design-lite-1>gulp serve
[21:20:30] Requiring external module babel-core/register
[21:20:38] Using gulpfile F:\stradorusite\MDL\material-design-lite-1\gulpfile.babel.js
[21:20:38] Starting 'serve'...
[21:20:46] Finished 'serve' after 8.5 s
[21:20:46] Server started http://localhost:5000
[21:20:46] LiveReload started on port 35729
[21:29:51] Server stopped
In [ ]:
#The following shorthands are parsed on the command-line:

-v: --version
-h, -?, --help, -H: --usage
-s, --silent: --loglevel silent
-q, --quiet: --loglevel warn
-d: --loglevel info
-dd, --verbose: --loglevel verbose
-ddd: --loglevel silly
-g: --global
-C: --prefix
-l: --long
-m: --message
-p, --porcelain: --parseable
-reg: --registry
-f: --force
-desc: --description
-S: --save
-D: --save-dev
-O: --save-optional
-B: --save-bundle
-E: --save-exact
-y: --yes
-n: --yes false
ll and la commands: ls --long

npmrc Files

The four relevant files are:

per-project config file (/path/to/my/project/.npmrc)
per-user config file (~/.npmrc)
global config file ($PREFIX/etc/npmrc)
npm builtin config file (/path/to/npm/npmrc) < See npmrc for more details.

Начнем с конца, вот пример команды поиска файла настроек .npmrc юзера (а их всего может быть 4 варианта).

In [ ]:
F:\stradorusite\MDL\material-design-lite>npm config list -l | find "userconfig"
userconfig = "C:\\Users\\alter_000\\.npmrc"

F:\stradorusite\MDL\material-design-lite>

You can get a list of all globally installed modules using:

Node has a concept of Local modules & Global modules

Local modules are located within current project directory.

Global Modules are genarally located at user's home directory, though we can change the path where global modules resides.

In [ ]:
#Lists local modules within current dir : 
    npm list
#Lists global modules : 
    npm list --global OR npm list --g 
    #// It will list all the top level modules with its dependencies

#List only top level(Installed modules) global modules : 
    npm list -g --depth=0
In [ ]:
ls `npm root -g`
In [ ]:
#One way might be to find the root directory of modules using:

npm root
/Users/me/repos/my_project/node_modules
In [ ]:
####Core modules are in node_modules in subfolders lib/ 

Node_modules contains user-installed packages so change the directory to node_modules and list the items. Core Modules are defined in node's source in the lib/ folder.

As of 13 December 2015

npm list illustration

Whilst I found the accepted answer 100% correct, and useful, wished to expand upon it a little based on my own experiences, and hopefully for the benefit of others too. (Here I am using the terms package and module interchangeably)

In answer to the question, yes the accepted answer would be:

In [ ]:
npm list -g --depth=0
#You might wish to check for a particular module installed globally, on *nix systems / when grep available. 
#This is particularly useful when checking what version of a module you are using (globally installed, 
#just remove the -g flag if checking a local module):

npm list -g --depth=0 | grep <module_name>
#If you'd like to see all available (remote) versions for a particular module, then do:

npm view <module_name> versions
#Note, versions is plural. This will give you the full listing of versions to choose from.

#For latest remote version:

npm view <module_name> version  
#Note, version is singular.

#To find out which packages need to be updated, you can use

npm outdated -g --depth=0
#To update global packages, you can use

npm install -g <package>
#To update all global packages, you can use:

npm update -g
In [ ]:
####
In [ ]:
F:\stradorusite\MDL\material-design-lite>npm list | find "babel"
+-- babel-core@6.10.4
| +-- babel-code-frame@6.11.0
| +-- babel-generator@6.11.0
| | +-- babel-types@6.11.1
| +-- babel-helpers@6.8.0
| +-- babel-messages@6.8.0
| +-- babel-runtime@6.9.2
| +-- babel-template@6.9.0
| | `-- babel-traverse@6.9.0
| +-- babel-traverse@6.10.4
| +-- babel-types@6.10.0
+-- babel-preset-es2015@6.9.0
| +-- babel-plugin-check-es2015-constants@6.8.0
| +-- babel-plugin-transform-es2015-arrow-functions@6.8.0
| +-- babel-plugin-transform-es2015-block-scoped-functions@6.8.0
| +-- babel-plugin-transform-es2015-block-scoping@6.10.1
| +-- babel-plugin-transform-es2015-classes@6.9.0
| | +-- babel-helper-define-map@6.9.0
| | +-- babel-helper-function-name@6.8.0
| | +-- babel-helper-optimise-call-expression@6.8.0
| | `-- babel-helper-replace-supers@6.8.0
| +-- babel-plugin-transform-es2015-computed-properties@6.8.0
| +-- babel-plugin-transform-es2015-destructuring@6.9.0
| +-- babel-plugin-transform-es2015-duplicate-keys@6.8.0
| +-- babel-plugin-transform-es2015-for-of@6.8.0
| +-- babel-plugin-transform-es2015-function-name@6.9.0
| +-- babel-plugin-transform-es2015-literals@6.8.0
| +-- babel-plugin-transform-es2015-modules-commonjs@6.8.0
| | `-- babel-plugin-transform-strict-mode@6.8.0
| +-- babel-plugin-transform-es2015-object-super@6.8.0
| +-- babel-plugin-transform-es2015-parameters@6.9.0
| | +-- babel-helper-call-delegate@6.8.0
| | | `-- babel-helper-hoist-variables@6.8.0
| | `-- babel-helper-get-function-arity@6.8.0
| +-- babel-plugin-transform-es2015-shorthand-properties@6.8.0
| +-- babel-plugin-transform-es2015-spread@6.8.0
| +-- babel-plugin-transform-es2015-sticky-regex@6.8.0
| | `-- babel-helper-regex@6.9.0
| +-- babel-plugin-transform-es2015-template-literals@6.8.0
| +-- babel-plugin-transform-es2015-typeof-symbol@6.8.0
| +-- babel-plugin-transform-es2015-unicode-regex@6.8.0
| `-- babel-plugin-transform-regenerator@6.9.0
|   `-- babel-plugin-syntax-async-functions@6.8.0
+-- babel-register@6.9.0
+-- gulp-babel@6.1.2
npm ERR! extraneous: google-closure-compiler@20160619.0.0 F:\stradorusite\MDL\material-design-lite\node_modules\google-closure-compiler

F:\stradorusite\MDL\material-design-lite>
In [ ]:
Just for clarity: in my case, there was one particular globally installed package that was the cause of this. I had to clean the cache after uninstalling the offending package, and cleaning the cache from within your projects directory might also be necessary (not only from your home directory).

Hard to pinpoint exactly what package it is sometimes. Nuclear option is to uninstall all global packages (make a note of them first), then navigate to working directory of any projects you have and clean cache from within each project directory. Now navigate to home directory, clean cache again and re-install all globally installed packages, running npm ls -g --depth=0 after each installation (do installs separately) to ensure it's not a bug in the package.

Long workaround, but worth a shot if it's really irking you.

Все конфигурационные настрйки надо узнавать вот так

In [ ]:
F:\stradorusite\MDL\material-design-lite>npm config list
; cli configs
user-agent = "npm/3.6.0 node/v5.6.0 win32 x64"

; builtin config undefined
prefix = "C:\\Users\\alter_000\\AppData\\Roaming\\npm"

; node bin location = C:\Program Files\nodejs\node.exe
; cwd = F:\stradorusite\MDL\material-design-lite
; HOME = C:\Users\alter_000
; "npm config ls -l" to show all defaults.
In [ ]:
F:\stradorusite\MDL\material-design-lite>npm config list -l
; cli configs
long = true
user-agent = "npm/3.6.0 node/v5.6.0 win32 x64"

; builtin config undefined
prefix = "C:\\Users\\alter_000\\AppData\\Roaming\\npm"

; default values
access = null
also = null
always-auth = false
bin-links = true
browser = null
ca = null
cache = "C:\\Users\\alter_000\\AppData\\Roaming\\npm-cache"
cache-lock-retries = 10
cache-lock-stale = 60000
cache-lock-wait = 10000
cache-max = null
cache-min = 10
cafile = undefined
cert = null
color = true
depth = null
description = true
dev = false
dry-run = false
editor = "notepad.exe"
engine-strict = false
fetch-retries = 2
fetch-retry-factor = 10
fetch-retry-maxtimeout = 60000
fetch-retry-mintimeout = 10000
force = false
git = "git"
git-tag-version = true
global = false
global-style = false
globalconfig = "C:\\Users\\alter_000\\AppData\\Roaming\\npm\\etc\\npmrc"
globalignorefile = "C:\\Users\\alter_000\\AppData\\Roaming\\npm\\etc\\npmignore"
group = 0
heading = "npm"
https-proxy = null
if-present = false
ignore-scripts = false
init-author-email = ""
init-author-name = ""
init-author-url = ""
init-license = "ISC"
init-module = "C:\\Users\\alter_000\\.npm-init.js"
init-version = "1.0.0"
json = false
key = null
legacy-bundling = false
link = false
local-address = undefined
loglevel = "warn"
; long = false (overridden)
message = "%s"
node-version = "5.6.0"
npat = false
onload-script = null
only = null
optional = true
parseable = false
; prefix = "C:\\Program Files\\nodejs" (overridden)
production = false
progress = true
proprietary-attribs = true
proxy = null
rebuild-bundle = true
registry = "https://registry.npmjs.org/"
rollback = true
save = false
save-bundle = false
save-dev = false
save-exact = false
save-optional = false
save-prefix = "^"
scope = ""
searchexclude = null
searchopts = ""
searchsort = "name"
shell = "C:\\WINDOWS\\system32\\cmd.exe"
shrinkwrap = true
sign-git-tag = false
strict-ssl = true
tag = "latest"
tag-version-prefix = "v"
tmp = "C:\\Users\\ALTER_~1\\AppData\\Local\\Temp"
umask = 0
unicode = false
unsafe-perm = true
usage = false
user = 0
; user-agent = "npm/{npm-version} node/{node-version} {platform} {arch}" (overridden)
userconfig = "C:\\Users\\alter_000\\.npmrc"
version = false
versions = false
viewer = "browser"



F:\stradorusite\MDL\material-design-lite>


Посты чуть ниже также могут вас заинтересовать

1 комментарий:

Анонимный комментирует...

Решение "подождать следующего релиза" оказалось верным... Сейчас с модулями babel- нет проблем