es6-modules

ESlint - import.meta causes Fatal Parsing Error

非 Y 不嫁゛ 提交于 2019-12-07 23:17:12
问题 Using the Atom editor, with the linter-eslint package installed, I'm have a node.mjs script that uses ES6 module's import statement to import various node modules. The script runs fine when I run it with node's --experimental-modules flag. However, while editing with Atom, linter-eslint says: Parsing error: Unexpected token import (Fatal) This parsing error is NOT being caused by the ecmascript "import" statements that I have at the top of my code file. Instead, it is actually caused by the

Which versions of iOS and Android webviews already support ES6 modules?

烂漫一生 提交于 2019-12-07 13:24:28
问题 I've been wondering which os/webview versions already support ES6 modules (import/export feature) natively without having to transpile to ES5 via webpack/babel. Please note that I'm asking about native webview support (for Cordova/PhoneGap) and not for mobile browser support such as Safari or Chrome. I heard that iOS 10.3 does support it but I'm not sure, also I'm absolutely clueless regarding the current state on Android. Couldn't find a clear answer googling around. Does someone have exact

How to import Firebase Firestore into a create-react-app project using ES6 syntax

橙三吉。 提交于 2019-12-07 11:40:42
问题 I'm having trouble getting Firebase Firestore to work with the basic create-react-app boilerplate. Does anyone have a working sample? The Get Started doc only explains how to set it up with require statements, whereas I'd like to use ES6 imports. const firebase = require("firebase"); // Required for side-effects require("firebase/firestore"); What is the ES6 equivalent of require('firebase/firestore') ? 回答1: This worked for me: import firebase from 'firebase/app'; import 'firebase/auth';

Why shouldn't you use import all in ES6

夙愿已清 提交于 2019-12-07 11:17:23
问题 So I recently started learning react and noticed that all the documentation has imports that look like else: import { Apples, Bananas, Oranges } from 'fruits'; But while studying react I found that this syntax works just as well: import * as Fruits from 'fruits'; My Question: Is there any performance loss or logical conflict with using the import all syntax? If there is not then I will just keep using that syntax. I would rather be a little more verbose and not have to worry about making sure

Is it possible to import a group of images as an array? (create-react-app project)

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-07 06:10:57
问题 Is it possible to import a group of images as an array? (create-react-app project) like written below but as a single-line? import Hat1 from '../../assets/img/accesories/hats/hat1.png'; import Hat2 from '../../assets/img/accesories/hats/hat2.png'; import Hat3 from '../../assets/img/accesories/hats/hat3.png'; import Hat4 from '../../assets/img/accesories/hats/hat4.png'; import Hat5 from '../../assets/img/accesories/hats/hat5.png'; import Hat6 from '../../assets/img/accesories/hats/hat6.png';

Import from node_modules not recognized in es6 modules in browser

ⅰ亾dé卋堺 提交于 2019-12-07 04:53:05
问题 I'm trying to use lodash in my web application. I have installed lodash using npm in my local project. I plan on using the ES6 modules in my code. Here is my main.js file: import * as _ from "lodash"; _.each([1, 2, 3, 4], (i) => { console.log('index each ' + i); }); And I have included it in index.html as: <script src="js/main.js", type="module"></script> But I get the following error in the browser console. Uncaught TypeError: Failed to resolve module specifier "lodash". Relative references

Jest: How to mock default export Component when same module also has named export?

旧时模样 提交于 2019-12-06 19:04:49
问题 I have an ES6 module that exports a React Component class by default, but also exports a plain JS function as a named export. When testing other packages that use this module, I want to mock both the default exported component and named exported function to keep my unit tests pure. The module looks something like this: import React, { Component } from 'react'; export default class MyComponent extends Component { render() { return <div>Hello</div> } } export function myUtilityFunction() {

Packaging Angular 5 UI-Components - Module not found

萝らか妹 提交于 2019-12-06 12:23:22
问题 I'm developing UI Components for usage in different Web-Projects across the company. We want to publish the components as npm package on our local Repository, ideally with sources included (for debugging). I found this article about exporting Angular Components and stick to it widely. Unfortunately, when I npm install and import the package in another project, the module is not found : import { TidUIComponentsModule } from '@tid/ui-components'; ERROR in src/app/app.module.ts(4,40): error

Import ES6 module elements directly or destructure const assignment following the import? [closed]

ⅰ亾dé卋堺 提交于 2019-12-06 09:22:37
Closed . This question is opinion-based . It is not currently accepting answers. Want to improve this question? Update the question so it can be answered with facts and citations by editing this post . Closed 3 years ago . Somewhat new to ES6 modules and find myself torn between the following 2 patterns... Pattern #1 - Destructuring on import import { func1, func2, func3 } from 'my-funcs'; Pattern #2 - Destructuring on const import * as myFuncs from 'my-funcs'; const { func1, func2, func3 } = myFuncs; I like the pattern #1 for its brevity, but I also like pattern #2 as it seems more explicit.

ES6 Modules and Circular Dependency

不羁岁月 提交于 2019-12-06 07:53:36
I'm having this problem in ES6 in a Babel Environment: // A.js class A { } export default new A(); // B.js import C from './C'; class B { } export default new B(); // C.js import A from './A'; import B from './B'; class C { constructor(A, B){ this.A = A; this.B = B; // undefined } } export default new C(A, B) I import them like this: // stores/index.js import A from './A'; import B from './B'; import C from './C'; export { A, B, C } And from my app entry point I do: import * as stores from './stores'; I would (hoped) expected the order of execution to be A -> B ->C but in reality it is A-> C->