我正在尝试安装 jsforce:
webpack 5.17.0 webpack-cli 4.4.0
无论我做什么,我都会收到以下错误:
ERROR in ./node_modules/jsforce/lib/oauth2.js 8:18-40
Module not found: Error: Can't resolve 'querystring' in '/var/www/pos/node_modules/jsforce/lib'
BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default.
This is no longer the case. Verify if you need this module and configure a polyfill for it.
If you want to include a polyfill, you need to:
- add a fallback 'resolve.fallback: { "querystring": require.resolve("querystring-es3") }'
- install 'querystring-es3'
If you don't want to include a polyfill, you can use an empty module like this:
resolve.fallback: { "querystring": false }
@ ./node_modules/jsforce/lib/core.js 12:17-36
@ ./node_modules/jsforce/lib/browser/jsforce.js 3:14-32
@ ./src/modules/checkout.js 4:0-30
@ ./src/index.js 3:0-45
(依此类推,还有其他 3 个模块)
我已经尝试了要求的步骤:
- 我已经安装了列出的所有 4 个软件包(browserify-stream、util、browserify-timers 和 querystring-es3)
- 我在 webpack.config.js 中添加了以下内容:
module.exports = {
...
resolve: {
fallback: {
"querystring": require.resolve("querystring-es3"),
"timers": require.resolve("timers-browserify"),
"util": require.resolve("util/"),
"stream": require.resolve("stream-browserify")
},
},
...
我重新启动了 webpack。一次又一次。没变。
我也从另一篇博客文章中尝试过这个:
resolve: {
alias: {
stream: "stream-browserify",
querystring: "querystring-es3",
timers: 'timers-browserify',
util: 'util'
}
},
也完全没有区别。
简而言之 - 提供的说明实际上都没有做任何事情。我已经完全按照说明完成了所有步骤,并且使用相同的说明继续遇到相同的错误。应该如何安装此模块?
这是我的整个 webpack 配置:
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
module.exports = {
resolve: {
alias: {
stream: "stream-browserify",
querystring: "querystring-es3",
timers: 'timers-browserify',
util: 'util'
}
},
mode: 'development',
experiments: {
topLevelAwait: true,
},
watch: true,
module: {
rules: [
{
test: /\.s?[ac]ss$/,
use: [
MiniCssExtractPlugin.loader,
{ loader: 'css-loader', options: { url: false, sourceMap: true } },
{ loader: 'sass-loader', options: { sourceMap: true } }
],
},{
test: /\.(woff(2)?|ttf|eot|svg)(\?v=\d+\.\d+\.\d+)?$/,
use: [{
loader: 'file-loader',
options: {
name: '[name].[ext]',
outputPath: 'font/'
}
}]
}
]
},
devtool: 'source-map',
plugins: [
new MiniCssExtractPlugin({
filename: "style.css"
})
],
resolve: {
alias: {
vue: 'vue/dist/vue.js'
},
},
};
和我的整个 package.json:
{
"dependencies": {
"file-loader": "^6.2.0",
"latest-version": "^5.1.0",
"postcss-loader": "^4.2.0",
"sass": "^1.32.5",
"sass-loader": "^10.1.1"
},
"name": "pos",
"version": "1.0.0",
"main": "webpack.config.js",
"devDependencies": {
"@stripe/terminal-js": "^0.5.0",
"bootstrap": "^5.0.0-beta1",
"bootstrap-icons": "^1.3.0",
"buffer": "^6.0.3",
"css-loader": "^5.0.1",
"jsforce": "^1.10.1",
"less-loader": "^7.3.0",
"mini-css-extract-plugin": "^1.3.4",
"querystring-es3": "^0.2.1",
"stream-browserify": "^3.0.0",
"style-loader": "^2.0.0",
"timers-browserify": "^2.0.12",
"util": "^0.12.3",
"vue": "^2.6.12",
"webpack": "^5.17.0",
"webpack-cli": "^4.4.0"
},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"private": true,
"author": "",
"license": "ISC",
"description": ""
}
我在我的入口文件中包含这样的 jsforce:
import jsforce from 'jsforce';