欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

Error: Cannot find module 'webpack/schemas/WebpackOptions.json'

程序员文章站 2022-06-01 12:47:17
...

1、错误原因

C:\Users\Administrator\cma>webpack you.js today.js
internal/modules/cjs/loader.js:573
    throw err;
    ^

Error: Cannot find module 'webpack/schemas/WebpackOptions.json'
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:571:15)
    at Function.Module._load (internal/modules/cjs/loader.js:497:25)
    at Module.require (internal/modules/cjs/loader.js:626:17)
    at require (C:\Users\Administrator\node_modules\v8-compile-cache\v8-compile-
cache.js:159:20)
    at Object.<anonymous> (C:\Users\Administrator\node_modules\webpack-cli\bin\c
onfig-yargs.js:1:85)
    at Module._compile (C:\Users\Administrator\node_modules\v8-compile-cache\v8-
compile-cache.js:178:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:689:10)
    at Module.load (internal/modules/cjs/loader.js:589:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:528:12)
    at Function.Module._load (internal/modules/cjs/loader.js:520:3)

C:\Users\Administrator\cma>

2、错误原因

     在使用webpack对JavaScript文件打包时,先是提示这个

One CLI for webpack must be installed. These are recommended choices, delivered
as separate packages:
 - webpack-cli (https://github.com/webpack/webpack-cli)
   The original webpack full-featured CLI.
 - webpack-command (https://github.com/webpack-contrib/webpack-command)
   A lightweight, opinionated webpack CLI.
We will use "npm" to install the CLI via "npm install -D".
Which one do you like to install (webpack-cli/webpack-command):

     选择了webpack-cli,进行了安装

Installing 'webpack-cli' (running 'npm install -D webpack-cli')...
npm WARN deprecated [email protected]: Package no longer supported. Contact [email protected]
pmjs.com for more info.
npm WARN rm not removing C:\Users\Administrator\node_modules\.bin\esparse.cmd as
 it wasn't installed by C:\Users\Administrator\node_modules\[email protected]@espri
ma
npm WARN rm not removing C:\Users\Administrator\node_modules\.bin\esparse as it
wasn't installed by C:\Users\Administrator\node_modules\[email protected]@esprima
npm WARN rm not removing C:\Users\Administrator\node_modules\.bin\esvalidate.cmd
 as it wasn't installed by C:\Users\Administrator\node_modules\[email protected]@es
prima
npm WARN rm not removing C:\Users\Administrator\node_modules\.bin\esvalidate as
it wasn't installed by C:\Users\Administrator\node_modules\[email protected]@esprim
a
npm WARN rm not removing C:\Users\Administrator\node_modules\.bin\coffee.cmd as
it wasn't installed by C:\Users\Administrator\node_modules\coffee-script
npm WARN rm not removing C:\Users\Administrator\node_modules\.bin\cake.cmd as it
 wasn't installed by C:\Users\Administrator\node_modules\coffee-script
npm WARN rm not removing C:\Users\Administrator\node_modules\.bin\coffee as it w
asn't installed by C:\Users\Administrator\node_modules\coffee-script
npm WARN rm not removing C:\Users\Administrator\node_modules\.bin\cake as it was
n't installed by C:\Users\Administrator\node_modules\coffee-script
npm WARN rm not removing C:\Users\Administrator\node_modules\.bin\semver.cmd as
it wasn't installed by C:\Users\Administrator\node_modules\[email protected]@semver
npm WARN rm not removing C:\Users\Administrator\node_modules\.bin\semver as it w
asn't installed by C:\Users\Administrator\node_modules\[email protected]@semver
npm WARN rm not removing C:\Users\Administrator\node_modules\.bin\rimraf.cmd as
it wasn't installed by C:\Users\Administrator\node_modules\[email protected]@rimraf
npm WARN rm not removing C:\Users\Administrator\node_modules\.bin\rimraf as it w
asn't installed by C:\Users\Administrator\node_modules\[email protected]@rimraf
npm WARN rm not removing C:\Users\Administrator\node_modules\.bin\mkdirp.cmd as
it wasn't installed by C:\Users\Administrator\node_modules\[email protected]@mkdirp
npm WARN rm not removing C:\Users\Administrator\node_modules\.bin\mkdirp as it w
asn't installed by C:\Users\Administrator\node_modules\[email protected]@mkdirp
npm WARN saveError ENOENT: no such file or directory, open 'C:\Users\Administrat
or\package.json'
npm WARN enoent ENOENT: no such file or directory, open 'C:\Users\Administrator\
package.json'
npm WARN [email protected] requires a peer of [email protected]^4.0.0 but none is install
ed. You must install peer dependencies yourself.
npm WARN Administrator No description
npm WARN Administrator No repository field.
npm WARN Administrator No README data
npm WARN Administrator No license field.

+ [email protected]
added 615 packages from 252 contributors, removed 615 packages and updated 30 pa
ckages in 139.557s
[!] 855 vulnerabilities found [13424 packages audited]
    Severity: 846 Low | 9 High
    Run `npm audit` for more detail

{ Error: Cannot find module 'webpack/schemas/WebpackOptions.json'
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:571:15)
    at Function.Module._load (internal/modules/cjs/loader.js:497:25)
    at Module.require (internal/modules/cjs/loader.js:626:17)
    at require (C:\Users\Administrator\node_modules\v8-compile-cache\v8-compile-
cache.js:159:20)
    at Object.<anonymous> (C:\Users\Administrator\node_modules\webpack-cli\bin\c
onfig-yargs.js:1:85)
    at Module._compile (C:\Users\Administrator\node_modules\v8-compile-cache\v8-
compile-cache.js:178:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:689:10)
    at Module.load (internal/modules/cjs/loader.js:589:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:528:12)
    at Function.Module._load (internal/modules/cjs/loader.js:520:3) code: 'MODUL
E_NOT_FOUND' }
      安装过程中,提示了很多不能移除,找不到相关的json文件

3、解决办法

     cnpm install --save-dev webpack

C:\Users\Administrator>cnpm install --save-dev webpack
\ [0/1] Installing [email protected]^1.3.0[[email protected]] download Error: GET
 http://registry.npm.taobao.org/fast-deep-equal/download/fast-deep-equal-2.0.1.t
gz response 504 status, fail count: 1
/ [0/1] Installing [email protected]^1.2.4[npminstall:get] retry GET http
s://registry.npm.taobao.org/uglifyjs-webpack-plugin after 100ms, retry left 4, e
rror: SyntaxError: Unexpected end of JSON input
- [0/1] Installing [email protected]^1.0.0[npminstall:get] retry GET https://regist
ry.npm.taobao.org/acorn after 100ms, retry left 4, error: ResponseError: socket
hang up (req "error"), GET https://registry.npm.taobao.org/acorn -1 (connected:
true, keepalive socket: false, agent status: {"createSocketCount":21,"createSock
etErrorCount":0,"closeSocketCount":3,"errorSocketCount":0,"timeoutSocketCount":1
,"requestCount":138,"freeSockets":{"registry.npm.taobao.org:443::::::::true:::::
:::":4},"sockets":{"registry.npm.taobao.org:443::::::::true::::::::":4,"cdn.npm.
taobao.org:443::::::::true::::::::":10},"requests":{"cdn.npm.taobao.org:443:::::
:::true::::::::":12}})
headers: {}
\ [0/1] Installing [email protected]^3.0.2platform unsupported [email protected] › watchpac
[email protected][email protected][email protected]^1.1.2 Package require os(darwin) not comp
atible with your platform(win32)
[[email protected]^1.1.2] optional install error: Package require os(darwin) not compati
ble with your platform(win32)
/ [0/1] Installing [email protected]^1.0.1[npminstall:get] retry GET ht
tps://registry.npm.taobao.org/move-concurrently after 100ms, retry left 4, error
: ResponseError: socket hang up (req "error"), GET https://registry.npm.taobao.o
rg/move-concurrently -1 (connected: true, keepalive socket: true, agent status:
{"createSocketCount":23,"createSocketErrorCount":0,"closeSocketCount":4,"errorSo
cketCount":0,"timeoutSocketCount":2,"requestCount":415,"freeSockets":{"registry.
npm.taobao.org:443::::::::true::::::::":8},"sockets":{"cdn.npm.taobao.org:443:::
:::::true::::::::":10,"registry.npm.taobao.org:443::::::::true::::::::":1},"requ
ests":{"cdn.npm.taobao.org:443::::::::true::::::::":16}})
headers: {}
\ [0/1] Installing [email protected]^1.4.0[npminstall:get] retry GET https://registry.npm.ta
obao.org/component-emitter after 100ms, retry left 4, error: ResponseError: sock
et hang up (req "error"), GET https://registry.npm.taobao.org/component-emitter
-1 (connected: true, keepalive socket: true, agent status: {"createSocketCount":
26,"createSocketErrorCount":0,"closeSocketCount":7,"errorSocketCount":0,"timeout
SocketCount":3,"requestCount":436,"freeSockets":{"registry.npm.taobao.org:443:::
:::::true::::::::":9},"sockets":{"cdn.npm.taobao.org:443::::::::true::::::::":10
},"requests":{"cdn.npm.taobao.org:443::::::::true::::::::":21}})
headers: {}
\ [0/1] Installing [email protected]^1.1.5[npminstall:get] retry GET https://registry.n
pm.taobao.org/run-queue after 100ms, retry left 4, error: ResponseError: socket
hang up (req "error"), GET https://registry.npm.taobao.org/run-queue -1 (connect
ed: true, keepalive socket: true, agent status: {"createSocketCount":26,"createS
ocketErrorCount":0,"closeSocketCount":14,"errorSocketCount":0,"timeoutSocketCoun
t":7,"requestCount":499,"freeSockets":{"cdn.npm.taobao.org:443::::::::true::::::
::":7,"registry.npm.taobao.org:443::::::::true::::::::":1},"sockets":{"cdn.npm.t
aobao.org:443::::::::true::::::::":3,"registry.npm.taobao.org:443::::::::true:::
:::::":1},"requests":{}})
headers: {}
/ [0/1] Installing [email protected]^1.1.1[npminstall:get] retry GET https://registry.npm.
taobao.org/p-limit after 100ms, retry left 4, error: ResponseError: socket hang
up (req "error"), GET https://registry.npm.taobao.org/p-limit -1 (connected: tru
e, keepalive socket: true, agent status: {"createSocketCount":27,"createSocketEr
rorCount":0,"closeSocketCount":25,"errorSocketCount":0,"timeoutSocketCount":17,"
requestCount":506,"freeSockets":{"cdn.npm.taobao.org:443::::::::true::::::::":1,
"registry.npm.taobao.org:443::::::::true::::::::":1},"sockets":{},"requests":{}}
)
headers: {}
√ Installed 1 packages
√ Linked 256 latest versions
√ Run 0 scripts
Recently updated (since 2018-05-25): 21 packages (detail see file C:\Users\Admin
istrator\node_modules\.recently_updates.txt)
  Today:
    → [email protected][email protected]^5.0.0(5.6.1) (15:49:17)
√ All packages installed (263 packages installed from npm registry, used 3m, sp
eed 26.89kB/s, json 257(1.73MB), tarball 3.23MB)

相关标签: webpack