gpt4 book ai didi

node.js - 模块内的 Webpack 未找到 Cheerio

转载 作者:太空宇宙 更新时间:2023-11-04 00:30:52 25 4
gpt4 key购买 nike

我正在使用scrape-it模块:https://github.com/IonicaBizau/scrape-it

我正在尝试将我的 js 与 webpack 捆绑在一起。但是,我遇到了这个错误:

ERROR in ./~/scrape-it/~/cheerio/index.js
Module not found: Error: Cannot resolve 'file' or 'directory' ./package in /Users/Spicycurryman/Desktop/Main/styell/node_modules/scrape-it/node_modules/cheerio
resolve file

完整堆栈跟踪:

ERROR in ./~/scrape-it/~/cheerio-req/~/cheerio/index.js
Module not found: Error: Cannot resolve 'file' or 'directory' ./package in /Users/Spicycurryman/Desktop/Main/styell/node_modules/scrape-it/node_modules/cheerio-req/node_modules/cheerio
resolve file
/Users/Spicycurryman/Desktop/Main/styell/node_modules/scrape-it/node_modules/cheerio-req/node_modules/cheerio/package doesn't exist
/Users/Spicycurryman/Desktop/Main/styell/node_modules/scrape-it/node_modules/cheerio-req/node_modules/cheerio/package.webpack.js doesn't exist
/Users/Spicycurryman/Desktop/Main/styell/node_modules/scrape-it/node_modules/cheerio-req/node_modules/cheerio/package.web.js doesn't exist
/Users/Spicycurryman/Desktop/Main/styell/node_modules/scrape-it/node_modules/cheerio-req/node_modules/cheerio/package.js doesn't exist
resolve directory
/Users/Spicycurryman/Desktop/Main/styell/node_modules/scrape-it/node_modules/cheerio-req/node_modules/cheerio/package doesn't exist (directory default file)
/Users/Spicycurryman/Desktop/Main/styell/node_modules/scrape-it/node_modules/cheerio-req/node_modules/cheerio/package/package.json doesn't exist (directory description file)
[/Users/Spicycurryman/Desktop/Main/styell/node_modules/scrape-it/node_modules/cheerio-req/node_modules/cheerio/package]
[/Users/Spicycurryman/Desktop/Main/styell/node_modules/scrape-it/node_modules/cheerio-req/node_modules/cheerio/package.webpack.js]
[/Users/Spicycurryman/Desktop/Main/styell/node_modules/scrape-it/node_modules/cheerio-req/node_modules/cheerio/package.web.js]
[/Users/Spicycurryman/Desktop/Main/styell/node_modules/scrape-it/node_modules/cheerio-req/node_modules/cheerio/package.js]
@ ./~/scrape-it/~/cheerio-req/~/cheerio/index.js 11:18-38

我有点困惑为什么会发生这种情况,因为所有适当的模块都存在。 这是我的 webpack.config.js 文件,它可能是问题的根源。

var webpack = require('webpack');
var path = require('path');
var fs = require('fs');
var request = require('request');
var CaseSensitivePathsPlugin = require('case-sensitive-paths-webpack-plugin');


module.exports = {
entry: "./main.js",
output: {
path: __dirname,
filename: "bundle.js"
},
module: {
loaders: [
{ test: /\.json$/, loader: 'json-loader' }
]
},
resolve: {
extensions: ['', '.webpack.js', '.web.js', '.js']
},
node: {
console: 'empty',
fs: 'empty',
net: 'empty',
tls: 'empty'
}
}

为什么会发生这种情况?如何解决这个问题?

最佳答案

我明白了。

我必须将'.json' 添加到resolve.extensions。

我现在收到了一个不相关的错误:

Using Webpack with Mongoose - mongoose.model is not a function

关于node.js - 模块内的 Webpack 未找到 Cheerio,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40987083/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com