目前,我正在尝试将node_module“网站抓取工具” [1]添加到我的Angular 4项目中。
我通过“ npm install website-scraper –save”下载并安装该模块。
在我的组件中,我通过“从Website-scraper导入*作为Scraper”导入模块。
到现在为止,所有内容都可以按预期进行编译。
如果现在我只是在组件的某处添加“ console.log(Scraper)”,则会收到警告[3],并且我的浏览器会引发错误[2]
有人可以启发我,怎么了?我使用节点8.9.0和npm 5.5.1。无论如何,我尝试了多个更老的node和npm版本(旧版本),导致了相同的行为。任何帮助表示赞赏。提前致谢。
[1] https://www.npmjs.com/package/website-scraper
[2] graceful-fs.js:166 Uncaught TypeError: Cannot read property 'prototype' of undefined
at patch (graceful-fs.js:166)
at Object.eval (graceful-fs.js:27)
at eval (graceful-fs.js:262)
at Object.../../../../graceful-fs/graceful-fs.js (vendor.bundle.js:884)
at __webpack_require__ (inline.bundle.js:55)
at eval (index.js:4)
at Object.../../../../fs-extra/lib/fs/index.js (vendor.bundle.js:726)
at __webpack_require__ (inline.bundle.js:55)
at eval (index.js:8)
at Object.../../../../fs-extra/lib/index.js (vendor.bundle.js:734)
at __webpack_require__ (inline.bundle.js:55)
at Object.eval (index.js:6)
at eval (index.js:69)
at Object.../../../../website-scraper/lib/resource-saver/index.js (vendor.bundle.js:3110)
at __webpack_require__ (inline.bundle.js:55)
at eval (scraper.js:16)
[3]: WARNING in ./node_modules/har-validator/node_modules/ajv/lib/async.js
119:15-28 Critical dependency: the request of a dependency is an expression
at CommonJsRequireContextDependency.getWarnings (C:\Users\XY\XYZ\MyProject\node_modules\webpack\lib\dependencies\ContextDependency.js:39:18)
at Compilation.reportDependencyErrorsAndWarnings (C:\Users\XY\XYZ\MyProject\node_modules\webpack\lib\Compilation.js:703:24)
at Compilation.finish (C:\Users\MyUser\MyProject\A1\node_modules\webpack\lib\Compilation.js:561:9)
at applyPluginsParallel.err (C:\Users\MyUser\MyProject\A1\node_modules\webpack\lib\Compiler.js:506:17)
at C:\Users\MyUser\MyProject\A1\node_modules\tapable\lib\Tapable.js:289:11
at _addModuleChain (C:\Users\MyUser\MyProject\A1\node_modules\webpack\lib\Compilation.js:507:11)
at processModuleDependencies.err (C:\Users\MyUser\MyProject\A1\node_modules\webpack\lib\Compilation.js:477:14)
at _combinedTickCallback (internal/process/next_tick.js:67:7)
at process._tickCallback (internal/process/next_tick.js:98:9)
@ ./node_modules/har-validator/node_modules/ajv/lib/async.js
@ ./node_modules/har-validator/node_modules/ajv/lib/ajv.js
@ ./node_modules/har-validator/lib/node4/promise.js
@ ./node_modules/request/lib/har.js
@ ./node_modules/request/request.js
@ ./node_modules/request/index.js
@ ./node_modules/website-scraper/lib/request.js
@ ./node_modules/website-scraper/lib/scraper.js
@ ./src/app/mytest/mytest.component.ts
@ ./src/app/app.module.ts
@ ./src/main.ts
@ multi webpack-dev-server/client?http://0.0.0.0:0 ./src/main.ts
WARNING in ./node_modules/har-validator/node_modules/ajv/lib/compile/index.js
13:21-34 Critical dependency: the request of a dependency is an expression
at CommonJsRequireContextDependency.getWarnings (C:\Users\MyUser\MyProject\A1\node_modules\webpack\lib\dependencies\ContextDependency.js:39:18)
at Compilation.reportDependencyErrorsAndWarnings (C:\Users\MyUser\MyProject\A1\node_modules\webpack\lib\Compilation.js:703:24)
at Compilation.finish (C:\Users\MyUser\MyProject\A1\node_modules\webpack\lib\Compilation.js:561:9)
at applyPluginsParallel.err (C:\Users\MyUser\MyProject\A1\node_modules\webpack\lib\Compiler.js:506:17)
at C:\Users\MyUser\MyProject\A1\node_modules\tapable\lib\Tapable.js:289:11
at _addModuleChain (C:\Users\MyUser\MyProject\A1\node_modules\webpack\lib\Compilation.js:507:11)
at processModuleDependencies.err (C:\Users\MyUser\MyProject\A1\node_modules\webpack\lib\Compilation.js:477:14)
at _combinedTickCallback (internal/process/next_tick.js:67:7)
at process._tickCallback (internal/process/next_tick.js:98:9)
@ ./node_modules/har-validator/node_modules/ajv/lib/compile/index.js
@ ./node_modules/har-validator/node_modules/ajv/lib/ajv.js
@ ./node_modules/har-validator/lib/node4/promise.js
@ ./node_modules/request/lib/har.js
@ ./node_modules/request/request.js
@ ./node_modules/request/index.js
@ ./node_modules/website-scraper/lib/request.js
@ ./node_modules/website-scraper/lib/scraper.js
@ ./src/app/mytest/mytest.component.ts
@ ./src/app/app.module.ts
@ ./src/main.ts
@ multi webpack-dev-server/client?http://0.0.0.0:0 ./src/main.ts
WARNING in ./node_modules/har-validator/node_modules/ajv/lib/async.js
96:20-33 Critical dependency: the request of a dependency is an expression
at CommonJsRequireContextDependency.getWarnings (C:\Users\MyUser\MyProject\A1\node_modules\webpack\lib\dependencies\ContextDependency.js:39:18)
at Compilation.reportDependencyErrorsAndWarnings (C:\Users\MyUser\MyProject\A1\node_modules\webpack\lib\Compilation.js:703:24)
at Compilation.finish (C:\Users\MyUser\MyProject\A1\node_modules\webpack\lib\Compilation.js:561:9)
at applyPluginsParallel.err (C:\Users\MyUser\MyProject\A1\node_modules\webpack\lib\Compiler.js:506:17)
at C:\Users\MyUser\MyProject\A1\node_modules\tapable\lib\Tapable.js:289:11
at _addModuleChain (C:\Users\MyUser\MyProject\A1\node_modules\webpack\lib\Compilation.js:507:11)
at processModuleDependencies.err (C:\Users\MyUser\MyProject\A1\node_modules\webpack\lib\Compilation.js:477:14)
at _combinedTickCallback (internal/process/next_tick.js:67:7)
at process._tickCallback (internal/process/next_tick.js:98:9)
@ ./node_modules/har-validator/node_modules/ajv/lib/async.js
@ ./node_modules/har-validator/node_modules/ajv/lib/ajv.js
@ ./node_modules/har-validator/lib/node4/promise.js
@ ./node_modules/request/lib/har.js
@ ./node_modules/request/request.js
@ ./node_modules/request/index.js
@ ./node_modules/website-scraper/lib/request.js
@ ./node_modules/website-scraper/lib/scraper.js
@ ./src/app/mytest/mytest.component.ts
@ ./src/app/app.module.ts
@ ./src/main.ts
@ multi webpack-dev-server/client?http://0.0.0.0:0 ./src/main.ts
最佳答案
您不能将website-scraper
直接添加到Angular项目中,因为它仅用于nodejs的服务器端使用。
我可以建议在服务器端使用它,并将结果返回给客户端。
这是一个如何在带有nodejs的服务器上使用website-scraper
并在客户端表示和成角度1的示例:https://github.com/website-scraper/demo