Tag: reactjs

如何使用babel与npm包将被反应使用

试图做我认为是一件简单的事情。 我有一个使用高级js语法的节点包。 我想依靠它在一个反应​​的项目。 所以我通过–save-dev安装了babel包,并添加了一个.babelrc : { "presets": ["env"], "plugins": ["transform-object-rest-spread"] } 这还不够,所以我在install添加了一个npm脚本来触发编译。 然后我不得不通过main包含编译目标lib/index.js作为我的入口点。 所以最后我的package.json看起来像这样: { "name": "bla", "version": "1.0.0", "scripts": { "postinstall": "babel src –out-dir lib" }, "main": "lib/index.js", "dependencies": {}, "devDependencies": { "babel-cli": "^6.26.0", "babel-plugin-transform-object-rest-spread": "^6.26.0", "babel-preset-env": "^1.6.1", "babel-preset-react-native": "^4.0.0" } } 当我在本地运行npm install ,它会正确地build立。 然而当反应脚本build立这个(dep是从github),我得到一个错误: sh: 1: babel: not found 。 为什么这么难? 我究竟做错了什么?

与NodeJS相比,使用Rails进行服务器端渲染会有更好的整体服务器响应时间吗?

我读过React.renderToString随着组件树数量和深度的增加而运行的时间越来越长,同步性阻止了节点服务器处理其他请求,因为它是单线程的,从而导致响应时间显着延长具有大量的并发请求。 使用其他后端,如本质上是multithreading的Rails可以显着提高整体服务器响应时间吗? 例如,Ruby有Execjs,允许它运行JavaScript。

`react-scripts test`返回码总是为零

有没有人知道如何在yarn test失败时在react应用程序中返回非零代码的yarn test (或npm test ) 在我的项目中,执行CI=true yarn test返回 Test Suites: 10 failed, 10 total Tests: 1 failed, 1 total Snapshots: 0 total Time: 1.736s Ran all test suites. Done in 2.34s. 所有testing失败。 但是这个命令返回了零码。 这使得travis-ci无法检测到失败的testing

编写一个基于反应的聊天应用程序,实时更新Express,Mongodb,Nodejs

我正在编写一个聊天应用程序的应用程序,它需要使用websockets或socket.io来检查服务器中的更新。 它会将信息传递给所有的客户。 GitHub存储库已连接。 我想弄清楚如何实现websockets / socket.io。 如果任何人都可以给我一些关于文件放置的提示,或者帮我弄明白,那将是太棒了。 链接到该项目: https : //github.com/vschool-september-2017/chatter

testing失败:ReferenceError:SpeechSynthesisUtterance未定义

我最近试图在我的项目中实现文本到Speech,并决定使用纯javascript的解决scheme。 ( https://developer.mozilla.org/en-US/docs/Web/API/SpeechSynthesisUtterance ) 我目前使用React@15.4.2和enzyme@2.9.1。 码: export default class DummyComponent extends React.Component { /* */ speak(text) { var synth = window.speechSynthesis; var utterThis = new SpeechSynthesisUtterance(text); synth.speak(utterThis); } /* */ } 一切工作正常,但每当我尝试testing我的代码,我得到的标题中的错误。 ExampleTest: it('dummytest', function(done){ const prop1 = 'foo'; const prop2 = 'bar'; const wrapper = shallow(<DummyComponent prop1 = {foo} prop2={bar}/>); expect(wrapper.html()).to.include("foobar"); done(); }); ReferenceError:SpeechSynthesisUtterance未定义 […]

即使预设了标题,所请求的资源上也不存在“Access-Control-Allow-Origin”标题

我从http:// localhost:3002服务器运行反应应用程序,并在http:// localhost:8080 / api / file中调用axios.post()动作来上传文件。 我使用expressJS作为后端。 还包括启用CORS的Cors模块。 app.use(cors({ origin: 'http://localhost:3002' })); 在客户端发出请求后,在chrome中显示以下错误 安慰 – ailed加载http:// localhost:8080 / api / file :否请求的资源上存在“Access-Control-Allow-Origin”头。 原因' http:// localhost:3002 '因此不被允许访问。 但是当我在networking上看到file upload并返回200 OK响应。 当我从expressJS中删除CORS头文件时,也是一样的。 如果请求完成,为什么显示CORS错误信息? 为什么不允许跨源请求,如果没有设置CORS头? 请帮忙!!!

获取错误“无法find预设'react-server'相对于目录…”

完整的错误信息: ../assets/around/TCircle.svg模块构build失败:错误:无法在Array.map(native)目录中find相对于目录“/ Users / admin / Documents”的预设“react-server” 我一遍又一遍地得到了上面的错误,但是在整个项目的目录中没有提到react-server。 我试图完成的是链接资产目录作为npm依赖,并访问他们在整个项目。 另外(这听起来可能很愚蠢) – 但它完全适用于其他人的机器。

React Express中的POST方法

我需要做的是:点击buttonadd用户后,我想诱导POST方法到数据库MySQL。 我必须从另一个文件连接到数据库比server.js,但我得到错误 Net.createConnection is not a function 这是我的Compontent文件 import React, { PropTypes} from 'react'; import { connect } from 'react-redux'; import { CounterActions } from '../redux/actions'; import { Link } from 'react-router' import mysql from 'mysql' var connection = mysql.createConnection({ host : 'xxx', user : 'xxx', password : 'xxx', database : 'xxx' }); connection.connect(function(error){ if(!!error){ […]

500内部服务器错误,表示反应mongo mern堆栈

您好我有我的反应组件中的registry单的麻烦,我用mongodb,这里是我的服务器,路由和注册组件我得到这个错误 xhr.js:178 POST http://localhost:3000/api/user/ 500 (Internal Server Error) dispatchXhrRequest @ xhr.js:178 xhrAdapter @ xhr.js:12 dispatchRequest @ dispatchRequest.js:59 Promise resolved (async) request @ Axios.js:51 Axios.(anonymous function) @ Axios.js:71 wrap @ bind.js:9 saveUser @ API.js:18 Signup._this.handleSubmit @ Signup.js:47 callCallback @ react-dom.development.js:540 invokeGuardedCallbackDev @ react-dom.development.js:579 invokeGuardedCallback @ react-dom.development.js:436 invokeGuardedCallbackAndCatchFirstError @ react-dom.development.js:450 executeDispatch @ react-dom.development.js:834 executeDispatchesInOrder @ react-dom.development.js:853 executeDispatchesAndRelease […]

如何与AdonisJs一起使用React.js

我如何在我的AdonisJs项目的前端使用React.js? 我试图安装反应与npm install react我认为这将正常工作。 我用这个代码做了一个文件app.js: var React = require('react'); var ReactDOM = require('react-dom'); export default class Index extends Component { render() { return (< h1 > hello world! < /h1>) } } ReactDOM.render( < Index / > , document.getElementById('example')) 但是这不起作用,我不知道该怎么做,我已经search了如何在阿多尼斯使用React,但我没有发现任何有趣的东西。