es6-module-loader

ES6 default and named exports

丶灬走出姿态 提交于 2021-02-18 22:41:25
问题 I am trying to understand named and default exports. I have a seemingly basic requirement which I don't understand how to setup. I want to be able to import both: //app.js import Mod from './my-module' import { funcA, funcB } from './my-module' console.log('A', Mod.funcA(), funcA()); // A a a console.log('B', Mod.funcB(), funcB()); // A a a When I try, the closest way of doing this I get to is the following: //my-module.js export function funcA() { return 'a'; }; export function funcB() {

ES6 default and named exports

时光总嘲笑我的痴心妄想 提交于 2021-02-18 22:39:36
问题 I am trying to understand named and default exports. I have a seemingly basic requirement which I don't understand how to setup. I want to be able to import both: //app.js import Mod from './my-module' import { funcA, funcB } from './my-module' console.log('A', Mod.funcA(), funcA()); // A a a console.log('B', Mod.funcB(), funcB()); // A a a When I try, the closest way of doing this I get to is the following: //my-module.js export function funcA() { return 'a'; }; export function funcB() {

JS - meaning of @ in import '@foo/bar'

我的未来我决定 提交于 2021-02-16 13:47:07
问题 While reading this article earlier, I came across the following line of code: import { run } from '@cycle/core'; Which led me to the following questions: What is the significance of the @ symbol, if any? Is there a difference between import 'foo/bar' and import '@foo/bar' ? Is it a way to resolve a particular type of module? I'm relatively new to ES6, although the import syntax seems pretty straightforward to me - except, in this case, for the cryptic presence of the @ symbol. I tried

Imported variable works but is not defined when accessed in debugger (within same scope)

為{幸葍}努か 提交于 2021-01-26 03:37:47
问题 I am using webpack + es6 to build my files. I exported modules in a Math.js, then imported in Main.js. In the latter, I used the module to compute, then set a stop in the debugger. The former worked but it was not defined when I tried to use it in the console. The scope is the same - why would the module not be defined in the console? // Math.js export function sum(x, y) { return x + y; } export var pi = 3.141593; // Main.js import * as mathTest from "./Math.js"; console.log("2π = " +

Exporting angularjs module as es6 module

∥☆過路亽.° 提交于 2020-07-17 11:04:34
问题 You are supposed to wrap angularjs modules in an IIFE according to the styleguide, which we use https://github.com/johnpapa/angular-styleguide/tree/master/a1#iife my-dir.js (function() { 'use strict'; angular .module('my.dir', []) .controller('MyDirController', MyDirController), .directive('my-dir', MyDirDirective); function MyDirController() { } function MyDirDirective() { return { restrict: 'E', controller: MyDirController } } })(); app.js (function() { 'use strict'; angular .module('app',

Publish ES module (.mjs) to NPMJS, with backwards compatibility for Node <8.5.0 (Dual Package)

心已入冬 提交于 2020-05-09 19:48:06
问题 Up to Node v8.5.0, publishing a module written in ES6 to NPMJS was a straightforward process: transpile the ES6 code using a tool like Babel, and publish to NPMJS the resulting lib directory, while your GitHub repo contains the src files. With v8.5.0, Node has released experimental support for native modules ( export / import ) via the --experimental-modules flag. It is now possible to publish purely-ES6 modules to NPMJS, and use them without any transpilation, as long as the files involved

“You may need an appropriate loader to handle this file type” with Webpack and Babel

人走茶凉 提交于 2020-04-23 06:34:22
问题 I am trying to use Webpack with Babel to compile ES6 assets, but I am getting the following error message: You may need an appropriate loader to handle this file type. | import React from 'react'; | /* | import { render } from 'react-dom' Here is what my Webpack config looks like: var path = require('path'); var webpack = require('webpack'); module.exports = { entry: './index', output: { path: path.join(__dirname, 'dist'), filename: 'bundle.js', publicPath: '/dist/' }, module: { loaders: [ {

“You may need an appropriate loader to handle this file type” with Webpack and Babel

落爺英雄遲暮 提交于 2020-04-23 06:27:31
问题 I am trying to use Webpack with Babel to compile ES6 assets, but I am getting the following error message: You may need an appropriate loader to handle this file type. | import React from 'react'; | /* | import { render } from 'react-dom' Here is what my Webpack config looks like: var path = require('path'); var webpack = require('webpack'); module.exports = { entry: './index', output: { path: path.join(__dirname, 'dist'), filename: 'bundle.js', publicPath: '/dist/' }, module: { loaders: [ {

npm test - Must use import to load ES Module - but I thought I was? (node 12)

空扰寡人 提交于 2020-02-29 06:41:27
问题 My files are all .mjs extension I have fizz_buzz.mjs and test/fizz_buzz.spec.mjs test/fizz_buzz.spec.mjs uses import { fizzBuzz } from '../fizz_buzz' I run npm test and I get > mocha test/**/*.spec.mjs /home/durrantm/Dropbox/90_2019/work/code/js/mocha_chai_bdd_tdd_exercises/node_modules/yargs/yargs.js:1163 else throw err ^ Error [ERR_REQUIRE_ESM]: Must use import to load ES Module: /home/durrantm/Dropbox/90_2019/work/code/js/mocha_chai_bdd_tdd_exercises/test/fizz_buzz.spec .mjs at Object

TypeError: __webpack_require__.i(…) is not a function

二次信任 提交于 2020-01-24 02:16:07
问题 I am getting a webpack TypeError when I am trying to simplify an import. The following code works without any issues. Here I am importing a React Higher-Order-Component (HOC) called smartForm from core/components/form/index.js . core/components/form/index.js (does a named export of smartForm ) export smartForm from './smart-form'; login-form.jsx (imports and uses smartForm ) import { smartForm } from 'core/components/form'; class LoginForm extends React.Component { ... } export default