How to stop babel from transpiling ‘this’ to ‘undefined’ (and inserting “use strict”)

For Babel >= 7.x ES6 code has two processing modes: “script” – When you load a file via a <script>, or any other standard ES5 way of loading a file “module” – When a file is processed as an ES6 module In Babel 7.x, files are parsed as “module” by default. The thing that is … Read more

Typescript compiler error when importing json file

Use var instead of import. var json = require(‘./calls.json’); You’re loading a JSON file, not a module, so import shouldn’t be used is this case. When var is used, require() is treated like a normal function again. If you’re using a Node.js definition, everything should just work, otherwise require will need to be defined.

TypeScript error in Angular2 code: Cannot find name ‘module’

Update If you use Typescript 2^ just use the following command: npm i @types/node –save-dev (instead of –save-dev you can just use shortcut -D) or install it globally: npm i @types/node –global You can also specify typeRoots or types in your tsconfig.json if you want but by default all visible “@types” packages are included in … Read more

How to handle circular dependencies with RequireJS/AMD?

This is indeed a restriction in the AMD format. You could use exports, and that problem goes away. I find exports to be ugly, but it is how regular CommonJS modules solve the problem: define(“Employee”, [“exports”, “Company”], function(exports, Company) { function Employee(name) { this.name = name; this.company = new Company.Company(name + “‘s own company”); }; … Read more

What is CommonJS and why should I care how it can help in writing .js applications? [closed]

CommonJS modules enables you to include javascript modules within the current scope and effectively keeps the global scope from being polluted. This massively reduces the chance of naming collisions and keeps code organised. That said I think it’s pretty safe to say that AMD modules have now become more popular than CommonJS. The RequireJS website … Read more

module.exports in typescript

You can export a single class in TypeScript like this: class Person { private firstName: string; private lastName: string; constructor(firstName: string, lastName: string) { this.firstName = firstName; this.lastName = lastName; } public getFullName() { return `${this.firstName} ${this.lastName}`; } } export = Person; And here is how it’s going to be used: var Person = require(‘./dist/commonjs/Person.js’); … Read more

Load “Vanilla” Javascript Libraries into Node.js

Here’s what I think is the ‘rightest’ answer for this situation. Say you have a script file called quadtree.js. You should build a custom node_module that has this sort of directory structure… ./node_modules/quadtree/quadtree-lib/ ./node_modules/quadtree/quadtree-lib/quadtree.js ./node_modules/quadtree/quadtree-lib/README ./node_modules/quadtree/quadtree-lib/some-other-crap.js ./node_modules/quadtree/index.js Everything in your ./node_modules/quadtree/quadtree-lib/ directory are files from your 3rd party library. Then your ./node_modules/quadtree/index.js file will just … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)