babeljs

Single React Component rendering with Babel Standalone with only index.html and Component

元气小坏坏 提交于 2020-02-21 11:57:06
问题 Noob with React here. I am playing around with React. I have a simple component to render inside my component.js. It is included in my index.html file. I included the scripts for React , ReactDOM , and babel in the head . I just want to see that one div render properly. I am not using Node yet, just a exercise with React and Babel (using babel-standalone). I am running the file with a simple http-server. I am getting an error with the React Chrome extension: Waiting for roots to load...to

Render images sources from parsed array of objects in react native

我们两清 提交于 2020-02-08 03:15:46
问题 I'm building a react native application which suppose to use some 'meta-data' objects as sources. I'm parsing each object in array and returning a JSX layout for each item . The only problem I have is how to provide sources from images, since I have them stored locally and need to require("link") them. My code gives me error: function loadModuleImplementation(moduleId, module) { moduleId = "../../../images/icons/photographer/Party.png" My code: class SelectScreen extends Component { props

SyntaxError on spread operator, while using babel env preset

耗尽温柔 提交于 2020-02-03 11:02:12
问题 I am trying to "modernize" mern.io starter bolerplate by replacing babel es2015 and stage-0 presets with env . However, it seems that env preset does not recognize the following snippet in client/modules/Intl/IntlReducer.js:9: import { enabledLanguages, localizationData } from '../../../Intl/setup'; import { SWITCH_LANGUAGE } from './IntlActions'; const initLocale = global.navigator && global.navigator.language || 'en'; const initialState = { locale: initLocale, enabledLanguages, ...

Re-export default in ES 6 modules

早过忘川 提交于 2020-01-30 15:20:08
问题 In ES6, is it possible to shorten the following code. I have an App.js file and an index.js . index.js import App from './App'; export default App; Something like this index.js export default App from './App.js' 回答1: If you use proposal-export-default-from Babel plugin (which is a part of stage-1 preset), you'll be able to re-export default using the following code: export default from "./App.js" For more information see the ECMAScript proposal. Another way (without this plugin) is: export {

How expose a exported function into global scope with babel and webpack

[亡魂溺海] 提交于 2020-01-28 08:59:24
问题 How can I compile my code with webpack and babel so that the exported function is available in the global scope. So for example: export function test(){console.log('test')} Should be available under window.test() . When I just run babel -d I got what I expect: 'use strict'; Object.defineProperty(exports, '__esModule', { value: true }); exports.test = test; function test() { console.log('test'); } but the webpack output looks like this: !function(e) { function t(r) { if (o[r])return o[r]

How to install Babel using Package Control on Sublime Text 3?

删除回忆录丶 提交于 2020-01-25 00:39:32
问题 I want to install Babel. I'm using a Mac, I already have Sublime Text 3 and Package Controll newly installed. So I tried cmd + shift + p to open up Package Controll and I typed " Install " but nothing shows up. I was following this link. I need Babel for React syntax highlighting. 回答1: You might what to check the file path of where Sublime 3 was placed. Did you sudo install? Perhaps this link will help. http://www.sublimetext.com/forum/viewtopic.php?f=3&t=12909 回答2: Had the same issue, in my

Vue - You may need an additional loader to handle the result of these loaders

房东的猫 提交于 2020-01-24 11:13:26
问题 I'using Vue and babel. I have an exported function //file a.js export async function get() { ... } i need to connect this exported function to a static method of MyClass // file b.js import myInterface from './a.js' export class MyClass { constructor() { ... } static myFunction = myInterface.get // <=== error line 36 } but i receive the following error: Module parse failed: Unexpected token (36:8) File was processed with these loaders: * ./node_modules/@vue/cli-plugin-eslint/node_modules

Cannot import .tsx file from .ts file (and vice versa)

邮差的信 提交于 2020-01-24 04:35:08
问题 I have a project with .ts and .tsx files and I am trying to import a .tsx file from a .ts file, like so: src/index.ts import WriteEditor from './write_editor'; src/write_editor.tsx import Events from './events'; import Actions from './actions'; export default class WriteEditor extends React.Component { /*...*/ } Now TypeScript tells me ERROR in ./src/index.ts Module not found: Error: Can't resolve './write_editor' in '/Users/luke/Projekte/writejs/code/writejs/src' @ ./src/index.ts 3:23-48 @

Unexpected import token - testing React Native with Jest

一世执手 提交于 2020-01-24 03:09:26
问题 I'm getting a weird import error when I try to test my react-native app with jest. I have babel-jest, babel-preset-react-native, jest, jest-react-native and react-test-render all installed but get this error message when I run npm test. ● Test suite failed to run /Users/maftalion/www/stars20/kiosk/node_modules/native-base/index.js:4 import Drawer from './Components/vendor/react-native-drawer'; ^^^^^^ **SyntaxError: Unexpected token import** at transformAndBuildScript (node_modules/jest

babel transpiled code use absolute imports

放肆的年华 提交于 2020-01-24 02:23:09
问题 Transpiling code using @babel/cli with the following command: babel --plugins @babel/plugin-transform-arrow-functions www/js/origin.js --out-file www/js/result.js produces a file which require imports using absolute path from my computer. Of course, running that on the server breaks as path is not found. Here is an example of absolute imports: import _slicedToArray from "/Users/myself/project/node_modules/@babel/runtime/helpers/builtin/es6/slicedToArray"; import _createClass from "/Users