javascript-GatsbyJS和Superagent:WebpackError:require不是函数
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了javascript-GatsbyJS和Superagent:WebpackError:require不是函数,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含2593字,纯文字阅读大概需要4分钟。
内容图文
我正在尝试使用gatsbyjs将我的react应用程序构建到静态html页面中.我刚刚尝试了“ gatsby build”,它经历了所有的事情,直到它想要创建静态页面,然后我得到:
error Building static HTML for pages failed
See our docs page on debugging HTML builds for help
1 | if (global.GENTLY) require = GENTLY.hijack(require); 2 |
> 3 | var crypto = require('crypto');
| ^ 4 | var fs = require('fs'); 5 | var util = require('util'), 6 | path = require('path'),
WebpackError: require is not a function
- incoming_form.js:3 Object.map../file
~/formidable/lib/incoming_form.js:3:1
- index.js:1 Object.<anonymous>
~/formidable/lib/index.js:1:1
- index.js:8 Object.<anonymous>
~/superagent/lib/node/index.js:8:1
- contact.js:3 Object.<anonymous>
src/pages/contact.js:3:1
- sync-requires.js:8 Object.exports.__esModule
.cache/sync-requires.js:8:53
我正在使用npm 5.5.1.
编辑:
因此,我只是在contact.js文件中注释掉了超级代理,然后构建顺利进行.但是,我不明白为什么这会引起任何问题:
contact.js:
import request from 'superagent'
export default class Contact extends React.Component {
constructor(props) {
super(props);
this.state = { showThankYou: false};
this.handleSubmit = this.handleSubmit.bind(this);
}
handleSubmit(e) {
e.preventDefault();
request.post('http://www.mywebsite.com/email.php')
.send(new FormData(document.getElementById('myForm')))
.end(function(err, res){
if (err || !res.ok) {
console.log('Oh no! error' + err);
} else {
console.log('yay got it');
}
});
document.getElementById("myForm").reset();
this.setState({showThankYou: true});
}
render() {
return (
<div className="row">
<div className="form_wrapper">
<div>
<form id="myForm" onSubmit={this.handleSubmit}>
<label htmlFor="fname">First Name</label>
<input type="text" id="fname" name="fname" />
<label htmlFor="lname">Last Name</label>
<input type="text" id="lname" name="lname" />
<label htmlFor="email">E-mail Address</label>
<input type="text" id="email" name="email" />
<label htmlFor="message">Message</label>
<textarea id="message" name="message" style={{height: "100px"}}></textarea>
<input type="submit" value="Submit" />
</form>
</div>
</div>
</div>);
}
}
解决方法:
我遇到了同样的错误(本例中是Auth0).我能够通过修改webpack配置来解决它.
盖茨比v1
在gatsby-node.js中添加:
exports.modifyWebpackConfig = ({ config, stage }) => {
config.plugin("webpack-define", webpack.DefinePlugin, [{ "global.GENTLY": false }])
return config;
};
盖茨比v2
在gatsby-node.js中添加:
exports.onCreateWebpackConfig = ({ stage, actions, plugins }) => {
actions.setWebpackConfig({
plugins: [
plugins.define({
'global.GENTLY': false
})
]
})
}
我最终遇到了其他问题,因为auth0-lock不支持服务器端渲染,但这解决了要求不是函数错误.
内容总结
以上是互联网集市为您收集整理的javascript-GatsbyJS和Superagent:WebpackError:require不是函数全部内容,希望文章能够帮你解决javascript-GatsbyJS和Superagent:WebpackError:require不是函数所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。