Tag: reactjs

无法在反应中继中获取列表

我正在遵循这里提到的相同的架构 我想要获取所有用户,所以我更新了我的模式 var Root = new GraphQLObjectType({ name: 'Root', fields: () => ({ user: { type: userType, resolve: (rootValue, _) => { return getUser(rootValue) } }, post: { type: postType, args: { …connectionArgs, postID: {type: GraphQLString} }, resolve: (rootValue, args) => { return getPost(args.postID).then(function(data){ return data[0]; }).then(null,function(err){ return err; }); } }, users:{ type: new […]

Electron和Webpack ENOENT:没有这样的文件或目录,打开“/path.txt”

我是一个初学者试图使用与Webpack捆绑在一起的Electron(以前的Atom)和Reactjs。 一切工作正常,直到我试图使用Electron的远程模块访问我的React组件中的mainWindow。 尝试导入这个模块,我得到臭名昭着的错误: Uncaught Error: ENOENT: no such file or directory, open '/path.txt' 我试过重新安装电子,我检查了node_modules / electron,发现path.txt在那里。 这是我的webpack.config.js: var webpack = require('webpack'); module.exports = { context: __dirname, entry: { app: ['webpack/hot/dev-server', './src/App.jsx'], }, target: 'node', output: { path: './public/built', filename: 'bundle.js', publicPath: 'http://localhost:8080/built/' }, devServer: { contentBase: './public', publicPath: 'http://localhost:8080/built/' }, module: { loaders: [ { […]

需要反应本地模块

我被困在一个反应​​本地项目的问题。 我试图做一个普通的需求文件,我出口所有的模块。 之后,我想只需要我的“require.js”文件,以避免在每个文件中这样require('../../ ModuleName')的调用。 我有4个文件: index.ios.js /app/home.js /app/MyView.js /app/require.js require.js: module.exports = { Home: require('./home'), MyView: require('./MyView') } 在index.ios.js中(他的模块Home和MyView正在正确导入) 'use strict'; var React = require('react-native'); var { AppRegistry, StyleSheet, Text, View, } = React; var { Home, MyView } = require('./app/require'); class Test_require extends React.Component { render() { return( <Home /> ); } } AppRegistry.registerComponent('Test_require', […]

Axios post request.body是空的对象

我正在尝试从我的反应中发布数据。 后端 – expression。 这是后端代码: var express = require('express'); var app = express(); var bodyParser = require("body-parser"); var methodOverride = require("method-override"); var mongoose = require("mongoose"); var expressSanitizer = require("express-sanitizer"); mongoose.connect("mongodb://localhost/blog-react"); //app config app.set("view engine", "ejs"); app.use(express.static("public")); app.use(bodyParser.urlencoded({extended: true})); //must be after parser app.use(expressSanitizer()); app.use(methodOverride("_method")); //schema config var blogSchema = new mongoose.Schema({ title: String, image: String, […]

React Jest示例不起作用

试图运行JesttestingReact代码的示例(从https://github.com/facebook/jest/tree/master/examples/react ),我得到以下错误: > @ test /home/aizquier/jest/examples/react > jest Using Jest CLI v0.7.1 FAIL __tests__/CheckboxWithLabel-test.js ● Runtime Error SyntaxError: /home/aizquier/jest/examples/react/__tests__/CheckboxWithLabel-test.js: Unexpected token (15:6) npm ERR! Test failed. See above for more details. testing在文件CheckboxWithLabel-test.js的第15行失败: jest.dontMock('../CheckboxWithLabel'); import React from 'react'; import ReactDOM from 'react-dom'; import TestUtils from 'react-addons-test-utils'; const CheckboxWithLabel = require('../CheckboxWithLabel'); describe('CheckboxWithLabel', function() { it('changes the text […]

Webpack:如何使用webpack-dev-server编译,写入磁盘并提供静态内容(js / css)

我想构build我的js / css代码,将它写在磁盘上,并使用webpack-dev-server在一个命令中提供。 我不想为生产模式设置另一台服务器。 我们该怎么做呢? 在下面分享我的webpack.config.js文件内容: module.exports = { watch: true, entry: [ './src/index.js' ], output: { path: __dirname +'/dist/', publicPath: '/dist/', filename: 'bundle.js' }, module: { loaders: [ { exclude:/(node_modules)/, loader: 'babel', query: { presets: ['es2015', 'react'] } } ] }, devServer: { historyApiFallback: true, contentBase: './' } }; 请在下面的package.json中find启动脚本: "start": "webpack-dev-server –progress –colors" […]

Flux扔分派器不是一个构造函数

我尝试使用jspm与reactjs。 我工作得很好。 但是当我把它与npm的flux包结合起来的时候。 那么它总是抛出Dispatcher不是一个构造函数错误。 我的代码如下 AppDispatcher.js import Flux from 'flux'; export default new Flux.Dispatcher(); StoreBase.js 'use strict'; import {EventEmitter} from 'events'; import AppDispatcher from '../dispatchers/AppDispatcher'; const CHANGE_EVENT = 'change'; export default class BaseStore extends EventEmitter { constructor() { super(); } subscribe(actionSubscribe) { this._dispatchToken = AppDispatcher.register(actionSubscribe()); } get dispatchToken() { return this._dispatchToken; } emitChange() { this.emit(CHANGE_EVENT); […]

如何运行与Nashorn反应的babel.transform?

我正在尝试使用babel.transform而不是JSXTranformer来做出反应。 … ScriptEngineManager mgr = new ScriptEngineManager(); ScriptEngine nashorn = mgr.getEngineByName("nashorn"); nashorn.eval("var process = {env:{}}"); // node-modules expect that nashorn.eval(getScript("com/facebook/babel/jvm-npm.js")); babel = (JSObject) nashorn.eval("require('babel');"); … Babel和babel-core被安装为全局节点模块,并且出现错误: testing套件:com.my.app.BabelTransformerTest 找不到模块./lib/api/node.js 无法加载模块babel-core LOAD_ERROR 无法加载模块babel LOAD_ERROR 无法加载模块babel-core LOAD_ERROR 无法加载模块babel LOAD_ERROR 找不到模块./lib/api/node.js 无法加载模块babel-core LOAD_ERROR 无法加载模块babel LOAD_ERROR ./lib/api/node.js位于C:\Users\***\AppData\Roaming\npm\node_modules 我听说有可能从Nashorn运行babel.transform ? 也许有只加载一个babel的特定模块作为JavaScript文件的方法?

{React jsx babel es6 webpack}我如何评论渲染(返回(// || / ** /))?

上周我开始了一个项目。 回到我的团队之前,我想评论我的代码。 /* Just for the Syntax outlook */ class Foo extends React.Components { constructor(props) { super(props); } render() { return ( <div className='bar'> /* <p> cannot commit!!!! </p> ** Following will throw error when bundled with webpack */ // This throws error as well. <div> ) } } <script src="https://cdnjs.cloudflare.com/ajax/libs/d3/3.4.11/d3.min.js"></script> 代码可能看起来像评论正在工作,但目前JSbin的设置没有在ES6上设置。 当你使用jsx通过webpack运行它时,会抛出一个错误。 这里是下面的堆栈 节点v6.0.0 […]

我可以使用sailsjs重新加载webpack的热模块吗?

我正在使用sails.js进行一个项目并作出反应 。 我希望能够使用Webpack的热模块更换,所以我可以编辑我的代码,并立即在浏览器上更改。 不过,我怎样才能把这一切联系起来似乎并不明显。 我希望能够使用$ sails lift并只是工作。 如果这是一个node.js项目,我简单地configurationwebpack使用react-transform-hmr并从package.json启动webpack-dev-server (例如这里所描述的 )。 但是,这似乎并不是一件非常有趣的事情。 我看到模块webpack-hot-middleware声称能够“在没有webpack-dev-server情况下将热重新加载到现有服务器”。 但是,我不确定在Sails> 0.10中添加Express中间件configuration的适当位置在哪里。 任何人都可以推荐一个好的方法来设置这个?