javascript-import

why node uses require not import?

核能气质少年 提交于 2020-01-13 08:58:10
问题 I'm learning node.js and am wondering why it uses the require syntax rather than the import syntax which React uses. i.e. const Validator = require("validator"); VS import Validator from "validator"; I believed import is es6 but I don't think that explains why it's not used in node. 回答1: the import and default are newer ES6 features, not yet used by node. Node is actually already implementing the new features as experiment though: with the --experimental-modules flag and only for files saved

ES6 import equivalent of require() without exports

蓝咒 提交于 2019-12-29 04:27:10
问题 By using require(./filename) I can include and execute the code inside filename without any export defined inside filename itself. What is the equivalent in ES6 using import ? Thanks 回答1: The equivalent is simply: import "./filename"; Here are some of the possible syntax variations: import defaultMember from "module-name"; import * as name from "module-name"; import { member } from "module-name"; import { member as alias } from "module-name"; import { member1 , member2 } from "module-name";

Destructuring assignment within import statements

你离开我真会死。 提交于 2019-12-24 08:25:35
问题 According to this source and a vague memory of having seen this sort of usage in a project somewhere, I'm curious if anyone has been able to do the following: import {map: { series }} from 'contra' As stated on this destructuring assignment overview: The import statement in ES6 behaves similarly to destructuring, but it is important to note that it is not actually destructuring. It appears that imports work a little different and perhaps one cannot expect the same exact behavior, but I haven

How does javascript import find the module without an extension?

浪尽此生 提交于 2019-12-10 17:38:40
问题 I understand that we can use import {x} from "./file" and a variable x will be imported from file.js in the same directory. How is this handled if there are files of the same name with different extensions in the directory? For example, if there were file.js and file.ts in the same directory, how would import {x} from "./file" behave? Would it depend on the version of javascript? 回答1: Would it depend on the version of javascript? No, it depends on the behavior of javascript runtime, that is,

How can I define a Webpack “global module” to hold my Knockout viewmodel?

╄→гoц情女王★ 提交于 2019-12-08 04:54:52
问题 I'm working on moving some legacy code into Webpack (to help me control some dependancy hell that I'm having. All's going well so far. The issue comes from the existing codes use of Knockout. I need a way to access the view model in various components. So I need something to hold this view model. This question seems to provide me a good solution: Put your variables in a module. Webpack evaluates modules only once, so your instance remains global and carries changes through from module to

When do we use '{ }' in javascript imports? [duplicate]

萝らか妹 提交于 2019-12-04 14:17:10
问题 This question already has answers here : When should I use curly braces for ES6 import? (9 answers) Closed last year . I am learning Javascript imports and I am yet to understand when we use curly braces while importing items(functions, objects, variables) from another JS file. import Search from './models/Search'; import * as searchView from './views/searchView'; import { elements, renderLoader } from './views/base' //elements is an object, renderLoader is a function 回答1: import { elements,

When do we use '{ }' in javascript imports? [duplicate]

陌路散爱 提交于 2019-12-03 08:18:43
This question already has an answer here: When should I use curly braces for ES6 import? 9 answers I am learning Javascript imports and I am yet to understand when we use curly braces while importing items(functions, objects, variables) from another JS file. import Search from './models/Search'; import * as searchView from './views/searchView'; import { elements, renderLoader } from './views/base' //elements is an object, renderLoader is a function import { elements, renderLoader } from './views/base' is the way you need to import single, named exports from a module, in this case it is

import jquery in angular4

≯℡__Kan透↙ 提交于 2019-11-29 02:30:29
in order to import jquery in an angualr4 project i do the following: npm install --save jquery npm install --save-dev @types/jquery in the app.component.ts import $ from 'jquery'; or import * as $ from 'jquery'; when run "ng serve" i got these errors ERROR in C:/jquery-angular/jqueryintegration/node_modules/@types/jquery/index.d.ts (47,40): ',' expected. ERROR in C:/jquery-angular/jqueryintegration/node_modules/@types/jquery/index.d.ts (2370,40): ',' expected. ..... ..... ..... ERROR in C:/jquery-angular/jqueryintegration/node_modules/@types/jquery/index.d.ts (4311,85): ';' expected. ERROR in

ES6 import equivalent of require() without exports

那年仲夏 提交于 2019-11-29 00:57:46
By using require(./filename) I can include and execute the code inside filename without any export defined inside filename itself. What is the equivalent in ES6 using import ? Thanks CodingIntrigue The equivalent is simply: import "./filename"; Here are some of the possible syntax variations: import defaultMember from "module-name"; import * as name from "module-name"; import { member } from "module-name"; import { member as alias } from "module-name"; import { member1 , member2 } from "module-name"; import { member1 , member2 as alias2 , [...] } from "module-name"; import defaultMember, {

import jquery in angular4

妖精的绣舞 提交于 2019-11-27 16:50:15
问题 in order to import jquery in an angualr4 project i do the following: npm install --save jquery npm install --save-dev @types/jquery in the app.component.ts import $ from 'jquery'; or import * as $ from 'jquery'; when run "ng serve" i got these errors ERROR in C:/jquery-angular/jqueryintegration/node_modules/@types/jquery/index.d.ts (47,40): ',' expected. ERROR in C:/jquery-angular/jqueryintegration/node_modules/@types/jquery/index.d.ts (2370,40): ',' expected. ..... ..... ..... ERROR in C: