babel

ES6 modules: imported constants are undefined at first; they become available later

陌路散爱 提交于 2019-11-30 00:57:45
问题 I use ES6 modules in my JavaScript application. The sources are compiled with webpack and babel. This is a shortened version of the file that causes me trouble: export const JUST_FORM = 0; export const AS_PAGE = 1; console.log(AS_PAGE); // ** export default function doSomething(mode = AS_PAGE) { console.log(mode); console.log(JUST_FORM); } I use this functionality just as you would expect. import doSomething, { AS_PAGE } from './doSomething' console.log(AS_PAGE); doSomething(); When I run the

How to use mobx in react-native 0.56 (Babel 7) with Decorators

懵懂的女人 提交于 2019-11-30 00:30:28
i've upgraded my RN app from 0.55.4 to 0.56 that use Babel 7. In 0.55.4 to use decorators for MOBX i use "babel-plugin-transform-decorators-legacy" but is not compatible with Babel 7... react-native ver: 0.56.0 mobx ver: 5.0.3 mobx-react ver: 5.2.3 does anyone have the solution? Thanks UPDATE: The app works in DEBUG with this configuration package.json ... "devDependencies": { "@babel/core": "7.0.0-beta.47", "@babel/plugin-proposal-decorators": "7.0.0-beta.47" ... } .babelrc { "presets": [ ["react-native"] ], "plugins": [ ["@babel/plugin-proposal-decorators", { "legacy": true }] ] } But in

Jest TypeError: Path must be a string. Received undefined

核能气质少年 提交于 2019-11-30 00:14:55
问题 Below settings for my package.json If I run from command line npm test all jest test cases are executed properly. In case I use directly the command jest from command line I receive this error: Test suite failed to run TypeError: Path must be a string. Received undefined at assertPath (path.js:7:11) at Object.relative (path.js:538:5) This happens on any test files. Any idea what could be wrong and how to fix it? "scripts": { "test": "standard && jest", "format": "standard --fix", "start":

babel vs babel-core vs babel-loader vs babel-preset-2015 vs babel-preset-react vs babel-polyfill

徘徊边缘 提交于 2019-11-29 23:36:27
I was setting up Webpack for my React project and got confused between babel , babel-core , babel-loader , babel-preset-2015 and babel-preset-react . I know that Babel is needed to transform ES7 or ES6 code to ES5 but in my package.json I have installed all these dependencies except Babel and they also as devDependencies . Can someone please explain what's the difference between all these and why all of them are needed for my project? Isn't there any single dependency to replace them all? And if they are so important, why are they included as devDependencies ? babel Babel doesn't do anything

babel安装问题,Cannot find module '@babel/core' babel-loader@8 requires Babel 7.x (the package '@babel/c

烈酒焚心 提交于 2019-11-29 22:10:38
Cannot find module '@babel/core' babel-loader@8 requires Babel 7.x (the package '@babel/core'). If you'd like to use Babel 6.x ('babel-core'), you should install 'babel-loader@7'.ou should install 'babel-loader@7'. 原因是: babel-loader和babel-core版本不对应所产生的, babel-loader 8.x对应babel-core 7.x babel-loader 7.x对应babel-core 6.x 也就是说,看你的版本,然后执行 npm i --save-dev babel-loader@7.1.5 你需要自己看一下babel-core的版本,去安装对应版本的babel-loader。 摘自:https://www.cnblogs.com/hoyong/articles/11057993.html 来源: https://www.cnblogs.com/hjbky/p/11537113.html

webpack初体验

本小妞迷上赌 提交于 2019-11-29 21:36:26
前提: 确保有node跟webpack 1.创建一个文件(webpack-demo),cmd进入控制台,使用指令npm init 会在项目中生成一个package.json文件。 2.在项目中安装webpack,在cmd中执行npm install --save-dev webpack。 这时候项目的初始化就完成,开始第一个demo。 在根目录先创建一个app文件夹一个public文件夹。在app文件夹内创建main.js以及Greeter.js,在public文件夹内创建index.html。 webpack简单打包指令: webpack { 打包文件 } -o { 文件位置 }。 在cmd执行 webpack app/main.js -o public/bundle.js 执行成功会在public文件夹中生成一个bundle.js文件。 通过配置文件使用webpack: 在跟目录创建webpack.config.js文件。 这时候只需要在cmd中执行webpack命令。这条命令会自动引用webpack.config.js文件中的配置项。 更快捷的方式: 配置我们一开始创建的package.json文件。npm可以引导任务执行,对npm进行配置后就可以更简单的使用。 在scripts中添加"start": "webpack"。 配置成功后在cmd中执 行npm start 即可成

Why does Async Await work with React setState?

天涯浪子 提交于 2019-11-29 20:41:53
I have been using async await with babel in my ReactJS project. I discovered a convenient use with React setState that I would just like to understand better. Consider this code: handleChange = (e) => { this.setState({[e.target.name]: e.target.value}) console.log('synchronous code') } changeAndValidate = async (e) => { await this.handleChange(e) console.log('asynchronous validation code') } componentDidUpdate() { console.log('updated component') } My intention was for the asynchronous validation code to run after the component has updated. And it works! The resulting console log shows:

es6总结

允我心安 提交于 2019-11-29 19:10:26
一、ES5 ES6区别 1、let和var定义变量的区别 javascript 严格模式 第一次接触let关键字,有一个要非常非常要注意的概念就是”JavaScript 严格模式”,比如下述的代码运行就会报错: let hello = 'hello world.'; console.log(hello); 错误信息如下: let hello = 'hello world.'; ^^^ SyntaxError: Block-scoped declarations (let, const, function, class) not yet supported outside strict mode ... 解决方法就是,在文件头添加”javascript 严格模式”声明: 'use strict'; let hello = 'hello world.'; console.log(hello); let和var关键字的异同 声明后未赋值,表现相同 'use strict'; (function() { var varTest; let letTest; console.log(varTest); //输出undefined console.log(letTest); //输出undefined }()); 使用未声明的变量,表现不同: (function() { console.log

method 'assign' not supported in IE, what to do

陌路散爱 提交于 2019-11-29 17:53:12
问题 I have a small /javascript,Babel script, that runs just fine in Chrome and Firefox browsers, but it fails in Internet Explorer 11. I hope somebody can help me. Here is my function: getDaysWithEvents() { // Get all the days in this months calendar view // Sibling Months included const days = this.getCalendarDays(); // Set Range Limits on calendar this.calendar.setStartDate(days[0]); this.calendar.setEndDate(days[days.length - 1]); // Iterate over each of the supplied events this.props.events

error: bundling failed: TypeError: Cannot read property 'bindings' of null

别等时光非礼了梦想. 提交于 2019-11-29 13:58:22
I am also facing a same issue while running the react-native app. The version i am using is as follows: React-Native:0.57.1 react-native-cli:2.0.1 node:v8.11.3 npm:5.6.0 Babel Version details: "devDependencies": { "@babel/runtime": "^7.0.0", "babel-jest": "20.0.3", "babel-preset-react-native": "^2.1.0", "jest": "20.0.4", "react-test-renderer": "16.0.0-alpha.12", "schedule": "^0.4.0" }, "jest": { "preset": "react-native" } } Error: error: bundling failed: TypeError: Cannot read property 'bindings' of null at Scope.moveBindingTo (/home/manish/Desktop/Practice/donut/node_modules/@babel/traverse