【发布时间】:2021-09-24 00:58:51
【问题描述】:
我正在尝试在我的 React 代码中使用 https://github.com/theophilusx/ssh2-sftp-client。我在const Client = require('ssh2-sftp-client');得到Uncaught TypeError: __webpack_require__(...).constants is undefined
代码:
const StfpTransfer = props => {
const filesToTransfer = props;
const Client = require('ssh2-sftp-client');
const config = {
host: 'XX.XX.XX.XXXX',
port: '22',
username: '********',
password: '********'
};
let sftp = new Client();
sftp.connect(config)
.then(() => {
return sftp.list('/storage/share');
})
.then(data => {
console.log(data);
})
.then(() => {
sftp.end();
})
.catch(err => {
console.error(err.message);
});
}
export default StfpTransfer;
我正在使用来自 App.js 的 StfpTransfer,并且在代码中只是首先尝试测试 sftp。
错误:
这是错误https://github.com/mscdex/ssh2/blob/master/lib/protocol/zlib.js的zlib
我想知道我在这里做错了什么?使用纯 javascript 模块或其他一些基本错误。我是 React/Nodejs 的初学者,所以欢迎任何建议。
编辑,如果有任何帮助,这里也是package.json:
{
"name": "draganddrop",
"version": "0.1.0",
"private": true,
"dependencies": {
"@testing-library/jest-dom": "^5.14.1",
"@testing-library/react": "^11.2.7",
"@testing-library/user-event": "^12.8.3",
"react": "^17.0.2",
"react-dom": "^17.0.2",
"react-scripts": "4.0.3",
"ssh2-sftp-client": "^7.0.0",
"web-vitals": "^1.1.2"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
},
"eslintConfig": {
"extends": [
"react-app",
"react-app/jest"
]
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
}
}
【问题讨论】:
标签: javascript node.js reactjs node-modules