babel

初识React项目遇到的坑(Uncaught ReferenceError: Set is not defined )

牧云@^-^@ 提交于 2019-11-27 13:39:11
**前言:每次在android、rn跟h5中切换的时候,代码总是会闹各种笑话,比如在rn中变量都是包含在“{}”只有一层花括号,但是在vue中“{{}}”会有两层花括号,样式的话rn是驼峰fontSize这种,但在h5中是font-size,然后在android中老喜欢把一个字符串定义为String a=‘123’,/苦笑,说多了都是泪啊,也做了1年多的rn了,总觉得自己react上手应该问题不大,哈哈,今天偶然看到app中有一个页面是用react写的,然后有一个bug,就是在部分手机(ios8、某米4)上,h5代码中一直报“Uncaught ReferenceError: Set is not defined ”,无奈只能自己去探索一下了,于是就照着react的官网创建了我的第一个react项目,哈哈~ ** 怎么样创建react项目我就不在这说了哈,跟着官网走,或者网上一搜一大把,我这里的demo是直接用的react的脚手架“create-react-app”创建的,然后我开心的把项目跑起来的: 然后跑到我的某米四手机上的时候,一片空白,唉唉~~ 很懵逼,于是adb连接电脑,然后用谷歌浏览器调试了一下,发现报错了: 好吧,看到这个bug的时候,我是既惊喜又慌乱,惊喜的是“项目中的h5的bug终于是在react工程中重现了”,慌乱的是"我该怎么解决这bug呢?",“set is

nodejs 8 import module - require or import? [duplicate]

天大地大妈咪最大 提交于 2019-11-27 11:57:05
问题 This question already has an answer here : NodeJS plans to support import/export es6 (es2015) modules (1 answer) Closed last year . Just wonder how do we import a module in node.js 8 - are we still using require ? Or do we still need babel for using import ? I have been digging around but seems no answer. If we still have to use require, why can't node implement import yet? 回答1: UPDATE-2018.11.15 ↓ Short answer We're still using require Long answer ESM loading has partially landed in node 8.5

Getting Unexpected Token Export

允我心安 提交于 2019-11-27 10:49:21
I am trying to run some ES6 code in my project but I am getting an unexpected token export error. export class MyClass { constructor() { console.log("es6"); } } Phil Ricketts You are using ES6 Module syntax. This means your environment (e.g. node.js) must support ES6 Module syntax. NodeJS uses CommonJS Module syntax ( module.exports ) not ES6 module syntax ( export keyword). Solution: Use babel npm package to transpile your ES6 to a commonjs target or Refactor with CommonJS syntax. In case you get this error it might also be related to how you included the javascript file into your html page.

博客从wordpress迁移到hexo

99封情书 提交于 2019-11-27 09:46:35
参考资料 https://www.jianshu.com/p/fd233d967e88 https://segmentfault.com/a/1190000005624504 https://github.com/theme-next/hexo-theme-next https://zhiho.github.io/2015/09/29/hexo-next/ http://theme-next.iissnan.com/getting-started.html https://blog.csdn.net/q2158798/article/details/82354154 https://www.jianshu.com/p/f068b8a36d84 基础环境 npm [root@wordpross ~]# npm -v 3.10.10 node [root@wordpross ~]# node -v v6.17.1 hexo [root@wordpross ~]# hexo version hexo-cli: 2.0.0 os: Linux 3.10.0-862.14.4.el7.x86_64 linux x64 http_parser: 2.8.0 node: 6.17.1 v8: 5.1.281.111 uv: 1.30.1 zlib: 1.2.7 ares: 1.10.1-DEV

webpack命令:Module build failed(from ./node_modules/babel-loader/lib/index.js)/405/错误解决

China☆狼群 提交于 2019-11-27 09:42:29
在项目中运行的时候出现报错,错误为Module build failed (from ./node_modules/babel-loader/lib/index.js) 解决方案: 控制台输入 npm install @babel/core @babel/preset-env 命令 即可解决 以上内容转摘自:https://www.cnblogs.com/xxflz/ 尼古拉斯-富贵 以下内容为自己使用心得: 在使用webpack打包时,编译器报错 【babel 405错误】,按照webpack的提示,重新install了babel等一系列工具,还是不行,最后在上述帖子中找到了解决的办法,上述内容不仅解决提到的问题,还可以解决babel: error 405 之类的错误,究其原因,是转换工具babel的问题,babel可以把我们的ES5转ES6,也可以ES6转ES5,很多转换,很烦杂 babel-preset-env 是一个新的 preset,可以根据配置的目标运行环境(environment)自动启用需要的 babel 插件。 目前我们写 javascript 代码时,需要使用 N 个 preset,比如:babel-preset-es2015、babel-preset-es2016。es2015 可以把 ES6 代码编译为 ES5,es2016 可以把 ES2016 代码编译为

SyntaxError: 'import' and 'export' may appear only with 'sourceType: module' - Wait what?

故事扮演 提交于 2019-11-27 09:12:53
So consider the following two files: app.js import Game from './game/game'; import React from 'react'; import ReactDOM from 'react-dom'; export default (absPath) => { let gameElement = document.getElementById("container"); if (gameElement !== null) { ReactDOM.render( <Game mainPath={absPath} />, gameElement ); } } index.js import App from './src/app'; The gulpfile.js var gulp = require('gulp'); var source = require('vinyl-source-stream'); var browserify = require('browserify'); var babelify = require("babelify"); var watch = require('gulp-watch'); gulp.task('make:game', function(){ return

Using babel to transpile to es3 (safari compliant)

两盒软妹~` 提交于 2019-11-27 07:13:18
问题 I am new to babel. I set it up like this: .babelrc: { "presets": ["es2015", "es2017"] } gulpfile: gulp.task('default', function() { return gulp.src(['src/**/*.js', '!src/**/3rd/*']) .pipe(babel()) .pipe(gulp.dest('dist')); }); However this seems to be compiling to es5 which is not fully supported in Safari. Is there a way to set target? So it can compile to ES3? 回答1: No, Babel does not support transpiling to ES3. Your options are: Compile to ES5 and then use ES5 shim. Use a different

web pack的使用事项

眉间皱痕 提交于 2019-11-27 06:58:39
一开始把webpack想的很难,很复杂,哈哈。 其实写的好的东西真的是越简单,越简单的东西其实越难写。 按照How to一步一步基本就能理解,webpack怎么使用了, 后面就是如何帮程序一步一步找到适配器。 但是也会遇到一些坑,需要我们一一跨过 比如: Parser.pp.raise ,遇到这样的问题基本都是babel没有升级。 "devDependencies": { "babel-core": "latest", "babel-loader": "^6.1.0", "babel-preset-es2015": "latest", "babel-preset-react": "latest", "babel-preset-stage-0": "latest", loaders: [ { test: /\.js$/, exclude: /(node_modules)/, loader: 'babel', query: {presets:[ 'es2015', 'react', 'stage-0' ]} }, 来源: http://www.cnblogs.com/wanghualiang/p/5339714.html

Module not found: Error: Cannot resolve module 'fs'

亡梦爱人 提交于 2019-11-27 06:27:22
问题 I'm making a react app using Babel and Webpack and I want to use the file-exists package from npm. I already installed and saved the package as a dependency for my project. After running npm start I get this error: ERROR in ./~/file-exists/index.js Module not found: Error: Cannot resolve module 'fs' in C:\GitHub\CryptoPrices\node_modules\file-exists @ ./~/file-exists/index.js 3:9-22 file-exists uses fs as a dependency but for some reason it is not working. Npm starts and runs without any

ES6环境搭配(一)

我的梦境 提交于 2019-11-27 05:59:47
一、Node(NodeJS、Node.js)的安装: 1、下载 官网下载地址: https://nodejs.org/en/ 2、安装 a、Linux 先将安装包解压,然后进行环境变量的配置即可 b、windows 按照默认步骤安装即可 查看是否安装成功: a、点击开始菜单查看应用程序 b、打开cmd命令窗口 使用命令 node -v或node --version 可以查看安装版本即安装成功 3、基本使用 执行某js文件代码: node 文件名或需要执行文件的路径 【 文件均为js文件 】 二、安装npm包管理工具 1、npm会随着node一起被安装到本地。可以使用以下命令来更新npm $ npm install npm@latest -g 2、安装淘宝镜像 由于默认npm的仓库在国外,下载起来很慢,可以使用淘宝镜像来加快下载速度。 $ npm install -g cnpm --registry=https://registry.npm.taobao.org Registry注册中心 官方:https://registry.npmjs.org 淘宝:https://registry.npm.taobao.org 私有:http://localIP:port 3、修改npm权限 a、windows下执行npm的时候遇到权限不足的情况: 打开cmd命令窗口时使用管理员的身份运行 b