在下面描述的工作区中,我无法构建没有package.json和ngx-的项目/插件。如果我更改为默认构建器,它的工作完全正常。工作区具有以下结构(为了清楚起见,大多数项目省略了):
- projects
- shared
- src
- lib
...
- package.json
...
- plugins
- src
- app
... plugin app is here
- webpack.config.js
- src
- app
... the main app is here
-webpack.config.js
-angular.json
-package.json我正在尝试实现角webpack-5模块联邦,下面是我的示例:
https://github.com/alexzuza/angular-plugin-architecture-with-module-federation
在这个示例中,项目/插件没有自己的package.json,并且使用命令ng构建插件构建它--prod没有任何问题。
我已经模仿了这个例子的结构,我的现有应用程序,以前没有项目文件夹。构建主应用程序不是问题。此外,建立共享图书馆的工作。然而,试图构建插件会产生:
'node-sass' usage is deprecated and will be removed in a future major version. To opt-out of the deprecated behaviour and start using 'sass' uninstall 'node-sass'.
- Generating browser application bundles...Compiling @angular/core : es2015 as esm2015
Compiling @angular/common : es2015 as esm2015
Compiling shared : es2015 as esm2015
Compiling @angular/platform-browser : es2015 as esm2015
Compiling @angular/platform-browser-dynamic : es2015 as esm2015
Compiling @angular/router : es2015 as esm2015
✔ Browser application bundle generation complete.
An unhandled exception occurred: ENOENT: no such file or directory, open '\package.json'
See "C:\Users\char-m\AppData\Local\Temp\ng-plu2me\angular-errors.log" for further details.
npm ERR! code ELIFECYCLE
npm ERR! syscall spawn
npm ERR! file C:\WINDOWS\system32\cmd.exe
npm ERR! errno ENOENT
npm ERR! NIS@0.0.0 build:plugins: `ng build plugins --prod`
npm ERR! spawn ENOENT
npm ERR!
npm ERR! Failed at the NIS@0.0.0 build:plugins script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\char-m\AppData\Roaming\npm-cache\_logs\2021-04-07T19_34_04_884Z-debug.log在上面的终端输出中单击“\package.json”可以打开工作区根目录中的package.json,没有问题。
将package.json从根复制到项目/插件/解决了这个问题。但是,我不想复制该文件。
编辑:如果我将角版本更新为旧版本(从11.1.1开始),如下所示:
Angular CLI: 11.0.7
Node: 14.15.1
OS: win32 x64
Angular: 11.0.0
... animations, cdk, common, compiler, compiler-cli, core, forms
... material, material-moment-adapter, platform-browser
... platform-browser-dynamic, platform-server, router
Ivy Workspace: Yes
Package Version
---------------------------------------------------------
@angular-devkit/architect 0.1100.7
@angular-devkit/build-angular 0.1100.7
@angular-devkit/core 11.0.7
@angular-devkit/schematics 11.0.7
@angular/cli 11.0.7
@angular/language-service 11.2.9
@schematics/angular 11.0.7
@schematics/update 0.1100.7
ng-packagr 11.2.4
rxjs 6.5.5
typescript 4.0.7
webpack 5.31.0建造成功了。但是,这不是一个选项,因为这会产生为应用程序提供服务时的另一个错误。
任何如何解决这一问题的想法都将受到高度赞赏。
文件角错误. like如下所示:
[error] HookWebpackError: ENOENT: no such file or directory, open '\package.json'
at makeWebpackError (C:\dev\nis\NIS\ClientApp\node_modules\webpack\lib\HookWebpackError.js:49:9)
at C:\dev\nis\NIS\ClientApp\node_modules\webpack\lib\Compilation.js:2394:12
at eval (eval at create (C:\dev\nis\NIS\ClientApp\node_modules\tapable\lib\HookCodeFactory.js:33:10), <anonymous>:31:1)
at fn (C:\dev\nis\NIS\ClientApp\node_modules\webpack\lib\Compilation.js:376:17)
at _next4 (eval at create (C:\dev\nis\NIS\ClientApp\node_modules\tapable\lib\HookCodeFactory.js:33:10), <anonymous>:28:1)
at eval (eval at create (C:\dev\nis\NIS\ClientApp\node_modules\tapable\lib\HookCodeFactory.js:33:10), <anonymous>:47:1)
at processTicksAndRejections (internal/process/task_queues.js:93:5)
-- inner error --
Error: ENOENT: no such file or directory, open '\package.json'
at Object.openSync (fs.js:476:3)
at Object.readFileSync (fs.js:377:35)
at CacheBackend.provideSync (C:\dev\nis\NIS\ClientApp\node_modules\enhanced-resolve\lib\CachedInputFileSystem.js:233:32)
at WebpackFileSystem.readFileAsUtf8 (C:\dev\nis\NIS\ClientApp\node_modules\license-webpack-plugin\dist\WebpackFileSystem.js:52:24)
at PluginChunkReadHandler.getPackageJson (C:\dev\nis\NIS\ClientApp\node_modules\license-webpack-plugin\dist\PluginChunkReadHandler.js:35:43)
at PluginChunkReadHandler.processModule (C:\dev\nis\NIS\ClientApp\node_modules\license-webpack-plugin\dist\PluginChunkReadHandler.js:45:40)
at C:\dev\nis\NIS\ClientApp\node_modules\license-webpack-plugin\dist\PluginChunkReadHandler.js:29:23
at WebpackModuleFileIterator.internalCallback (C:\dev\nis\NIS\ClientApp\node_modules\license-webpack-plugin\dist\WebpackModuleFileIterator.js:28:13)
at WebpackModuleFileIterator.iterateFiles (C:\dev\nis\NIS\ClientApp\node_modules\license-webpack-plugin\dist\WebpackModuleFileIterator.js:8:9)
at C:\dev\nis\NIS\ClientApp\node_modules\license-webpack-plugin\dist\PluginChunkReadHandler.js:27:32文件2021-0407T19_34_04_884Z-调试器。日志如下所示:
0 info it worked if it ends with ok
1 verbose cli [
1 verbose cli 'C:\\Program Files\\nodejs\\node.exe',
1 verbose cli 'C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js',
1 verbose cli 'run',
1 verbose cli 'build:plugins'
1 verbose cli ]
2 info using npm@6.14.8
3 info using node@v14.15.1
4 verbose run-script [ 'prebuild:plugins', 'build:plugins', 'postbuild:plugins' ]
5 info lifecycle NIS@0.0.0~prebuild:plugins: NIS@0.0.0
6 info lifecycle NIS@0.0.0~build:plugins: NIS@0.0.0
7 verbose lifecycle NIS@0.0.0~build:plugins: unsafe-perm in lifecycle true
8 verbose lifecycle NIS@0.0.0~build:plugins: PATH: C:\Program Files\nodejs\node_modules\npm\node_modules\npm-lifecycle\node-gyp-bin;C:\dev\nis\NIS\ClientApp\node_modules\.bin;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\WINDOWS\System32\OpenSSH\;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files\Git\cmd;C:\Program Files\Git\mingw64\bin;C:\Program Files\Git\usr\bin;C:\Program Files\nodejs\;C:\Program Files\Microsoft SQL Server\130\Tools\Binn\;C:\Program Files\Microsoft SQL Server\Client SDK\ODBC\170\Tools\Binn\;C:\Program Files (x86)\Microsoft SQL Server\150\DTS\Binn\;C:\Program Files\Azure Data Studio\bin;C:\Program Files (x86)\Yarn\bin\;C:\Program Files\Microsoft\Web Platform Installer\;C:\Program Files\dotnet\;C:\Program Files (x86)\dotnet\;C:\Users\char-m\AppData\Local\Microsoft\WindowsApps;;C:\Users\char-m\AppData\Local\Programs\Microsoft VS Code\bin;C:\Users\char-m\AppData\Roaming\npm;C:\Program Files\Azure Data Studio\bin;C:\Users\char-m\AppData\Local\Yarn\bin;C:\Users\char-m\.dotnet\tools
9 verbose lifecycle NIS@0.0.0~build:plugins: CWD: C:\dev\nis\NIS\ClientApp
10 silly lifecycle NIS@0.0.0~build:plugins: Args: [ '/d /s /c', 'ng build plugins --prod' ]
11 info lifecycle NIS@0.0.0~build:plugins: Failed to exec build:plugins script
12 verbose stack Error: NIS@0.0.0 build:plugins: `ng build plugins --prod`
12 verbose stack spawn ENOENT
12 verbose stack at ChildProcess.<anonymous> (C:\Program Files\nodejs\node_modules\npm\node_modules\npm-lifecycle\lib\spawn.js:48:18)
12 verbose stack at ChildProcess.emit (events.js:315:20)
12 verbose stack at maybeClose (internal/child_process.js:1048:16)
12 verbose stack at Process.ChildProcess._handle.onexit (internal/child_process.js:288:5)
13 verbose pkgid NIS@0.0.0
14 verbose cwd C:\dev\nis\NIS\ClientApp
15 verbose Windows_NT 10.0.18363
16 verbose argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "run" "build:plugins"
17 verbose node v14.15.1
18 verbose npm v6.14.8
19 error code ELIFECYCLE
20 error syscall spawn
21 error file C:\WINDOWS\system32\cmd.exe
22 error errno ENOENT
23 error NIS@0.0.0 build:plugins: `ng build plugins --prod`
23 error spawn ENOENT
24 error Failed at the NIS@0.0.0 build:plugins script.
24 error This is probably not a problem with npm. There is likely additional logging output above.
25 verbose exit [ 1, true ]发布于 2021-06-23 12:04:39
我正在使用NX工作区,我也面临着同样的问题。看了webpack的医生后,我可以设法解决这个问题。
我所做的是,我在构建命令的末尾使用了--no-extract-licenses,这非常有效。
nx :nx build yourAppName --prod
After:nx build yourAppName --prod --不提取--许可证
希望这对你也有用..。
发布于 2022-09-07 13:20:17
我使用的是nx,问题是我删除了应用程序文件夹,但没有从angular.json文件中删除条目。
如果上面的方法对你不起作用,你可能会想试一试。
https://stackoverflow.com/questions/66991996
复制相似问题