Tag: babel

如何使用es6语法将快速模块作为函数导入?

在当前版本的节点中,导入模块的function如下所示: // case 1: const MongoStore = require('connect-mongo')(session) // case: 2 const LocalStrategy = require('passport-local').Strategy 但是,我在我的express服务器中使用es2015语法,如下所示: import MongoStore from 'connect-mongo' import LocalStrategy from 'passport-local' 我如何将会话作为函数parameter passing给import语句,或者追加Strategy方法?

使导出默认使用Babel,webpack和Node.js

我无法弄清楚为什么我的代码不起作用。 我正在构build一个ES6风格的类,并希望导出它能够在服务器端的其他地方使用它。 我把代码放到一个名为PlayerManager.js的server文件夹中。 我把我的客户端代码放在src文件夹中。 而我的服务器代码在我的server文件夹和server文件夹外的server.js 。 这是目录结构: Root – dist – node_modules – public – server – src server.js webpack.base.js webpack.dist.js package.json .babelrc PlayerManager.js文件: class PlayerManager { constructor() { if (! PlayerManager.instance) { this.playerList = {}; this.bulletList = {}; this.initPack = {player: [], bullet: []}; this.removePack = {player: [], bullet: []}; PlayerManager.instance = this; } […]

在运行heroku本地网时,babel-node无法识别

我尝试在Heroku上部署Node.js API,但显示应用程序错误。 因此,使用“ heroku本地networking ”命令来testing任何错误..并得到一个错误,说'babel节点'不被识别为内部或外部命令,可操作的程序或batch file。 另一方面,当我运行命令'npm start'时,我没有得到任何错误,服务器开始运行。 的package.json { "name": "apollo-starter-kit", "version": "0.1.0", "description": "Minimal set of code to write a GraphQL server with Apollo graphql-tools", "scripts": { "start": "nodemon ./server.js –exec babel-node", "test": "echo \"Error: no test specified\" && exit 1", "lint": "eslint ." }, "repository": { "type": "git", "url": "git+https://github.com/apollostack/apollo-starter-kit.git" }, "keywords": […]

Webpack&Babel:服务器端渲染React组件“Unexpected token”<'“

我一直在调查这个问题3天,但不能得到它的工作。 完整的错误是: C:\Users\XXXXXX\WebstormProjects\XXXX\server\routes\auth.jsx:58 return res.send(ReactDOMServer.renderToString(<LoginPage />)); ^ SyntaxError: Unexpected token < at createScript (vm.js:56:10) at Object.runInThisContext (vm.js:97:10) at Module._compile (module.js:542:28) at Object.Module._extensions..js (module.js:579:10) at Module.load (module.js:487:32) at tryModuleLoad (module.js:446:12) at Function.Module._load (module.js:438:3) at Module.require (module.js:497:17) at require (internal/module.js:20:19) at Object.<anonymous> (C:\Users\XXXXXX\WebstormProjects\XXXX\index.js:10:20) 这是我的webpack.config.js: const path = require('path'); module.exports = { entry: path.join(__dirname, '/client/src/app.jsx'), output: { path: […]

在Node.js中导入React throws SyntaxError:意外的令牌导出

我试图用Node.js和React实现SSR,按照这个例子https://github.com/babel/example-node-server的build议,在官方的Babel文档中这里http://babeljs.io/docs/usage / CLI /#巴别节点 为了开发,我使用了babel-node ; 为了生产,我想用babel来传递我的服务器并运行它: 的package.json "scripts": { "start": "node ./dist/server/index.js", "dev:server": "nodemon ./src/server/index.js -x babel-node", "build:server": "babel ./src/server -d ./dist/server –copy-files -s inline" }, "babel": { "presets": [ "env", "react", "stage-2" ], "plugins": [ "transform-decorators-legacy" ] } 服务器使用ES6语法编写: SRC /服务器/ index.js import 'babel-polyfill' import './config' import Express from 'express' import bootstrap from […]

您应该通过在Babelconfiguration中使用`env`部分禁用生产中的react-transform-hmr

我使用babel-cli来获得jsx和es6的function 我已经改变了我的构build命令 从 "build": "node build", 至 "build": "babel-node build" , 以前一切正常 但是,当我运行生成命令我得到这个错误 错误:locals [0]似乎不是启用热模块replaceAPI的module对象。 您应该通过在Babelconfiguration中使用env部分来禁用生产中的react-transform-hmr。 请参阅自述文件中的示例: https : //github.com/gaearon/react-transform-hmr 也看截图 所以我应该通过在Babelconfiguration中使用env部分来禁用生产中的react-transform-hmr 这是我的.babelrc喜欢的说明 { "presets": ["react", "es2015"], "env": { "development": { "plugins": [ ["transform-object-rest-spread"], ["transform-react-display-name"], ["react-transform", { "transforms": [{ "transform": "react-transform-hmr", "imports": ["react"], "locals": ["module"] }, { "transform": "react-transform-catch-errors", "imports": ["react", "redbox-react"] }] }] ] […]

通过browserify reactjs包脚本不工作在客户端(未捕获ReferenceError:组件未定义)

我尝试使用node.js和reactjs作为我的PHP后端模板呈现服务。 这是指导原则 。 我想知道是否有一个问题,我build立了由bundle.js 。 我得到Uncaught ReferenceError: ItemPage is not defined在客户端,因为组件ItemPage不是全局的bundle.js ,但我不知道如何访问它,因为它被包裹在一些我真的不需要的函数理解。 这是我的es6组件脚本: import React from 'react'; import Tabs from 'grommet/components/Tabs'; import Tab from 'grommet/components/Tab'; class ItemPage extends React.Component { render(){ return <Tabs onClick={this._onClick.bind(this)}> <Tab title="First Title"> <h3>First Tab</h3> <p>Contents of the first tab !</p> <div>Something@@@@@@</div> </Tab> <Tab title="Second Title"> <h3>Second Tab</h3> <p>Contents of the […]

在浏览器中使用babel-standalone

我正在使用babel-standalone而且我正在做与https://github.com/Daniel15/babel-standalone/blob/master/examples/scriptTag-src.htm完全相同的事情,但是我收到警告 您正在使用浏览器中的Babel变换器。 一定要预编译您的脚本生产 – https://babeljs.io/docs/setup/ 我不知道该怎么办。 不应该只是将我所有的ES6代码转换成旧版浏览器支持的代码?

nodemon,babel-node:如何设置环境variables?

开发环境从这个命令开始: nodemon -w src –exec \"babel-node src –presets es2015,stage-0\" 我如何创build一个全局variables(或process.envvariables) __DEV__ = true ?

在节点6中使用不带巴别的导入关键字

我想知道为什么Node.js node index.js引发以下错误: (function (exports, require, module, __filename, __dirname) { import * as math from "lib/math"; ^^^^^^ SyntaxError: Unexpected token import at Object.exports.runInThisContext (vm.js:53:16) at Module._compile (module.js:513:28) at Object.Module._extensions..js (module.js:550:10) at Module.load (module.js:458:32) at tryModuleLoad (module.js:417:12) at Function.Module._load (module.js:409:3) at Function.Module.runMain (module.js:575:10) at startup (node.js:160:18) at node.js:456:3 甚至, node -v显示6.2.1 。 即使我们使用节点6(6.2.1), import关键字是否受Babel限制?