When I put "export module" in a .ts file, it says I need to add --module.
That requires a KIND. If I'm using TypeScript, RequireJS, and Ext JS, is amd the correct kind?
Yes AMD is what RequireJS expects.
Related
I started seeing:
(node:6420) Warning: require() of ES modules is not supported.
when starting my webpack build and was wondering if using all import export for webpack.config.js was supported yet.
edit 1: I want to know if it's supported without using #babel/register or other transforms
Is is supported in Node 13. You can use either the .mjs extension (for files where you need to use import/export), or set "type": "module" in your package.json.
If your code runs in Node, you can use the fs package to interact with the file system
I am trying to convert Express.js project to binary, and I am using zeit/pkg libary. However, it gave me an error every time I try to use pkg.
Is there a way that I can force Node/Npm to use es5 instead of es6.
in your snapshot the module is being imported from ..er/node_modules/safefs/es6/lib/safefs.js
notice it is importing from es6 which has export keyword. that means its an es6 module and your node supports 'commonjs' require.
which is why this require may be failing.
you can download latest version of node where you can resolve es6 modules.
I am using koa framework of node.js. I have implemented my code using typescript. I have created .ts files for the same and I am using tsc compiler to compile it.
Should I use babel or tsc for compiling the code?
Before sometime, I read about babel. Now, I have a doubt wheather to use babel or tsc for compiling the code. Please suggest.
Both are excellent choices.
Babel: Main focus is transpiler
TypeScript: In addition to be a transpiler main focus is a type checker.
Opinion
I prefer TypeScript for reasons covered here 🌹
ts-node suggests to use require('ts-node/register'). And this can be seen in angular2-webpack-starter Protractor configuration.
What is require('ts-node/register') supposed to do? Does it patch require to transpile TS files, so a part of Node.js application could be written in TypeScript?
It does what you think it does. require('ts-node/register') is actually the same as:
require('./').register({
lazy: true
})
See examples here: https://github.com/TypeStrong/ts-node/tree/master/register
The .register function registers the Typescript compiler for files with .ts and .tsx extension for compilation on the fly.
I'm using WebStorm to build a Node.js app in TypeScript. When I write a "require" statement, the TypeScript compiler uses AMD. I know it by the js output with the asynchronous pattern.
How can I tell WebStorm to use CommonJS instead?
I'm not a WebStorm user myself, but I think WebStorm refers to the tsconfig.json file at the root of your TypeScript project for this type of compiler configuration.
Here's the documentation for the tsconfig.json file.
If this file doesn't already exist in your project, create one in the root of your TypeScript compilation directory. In this file, you can tell the compiler which module system to use with the module parameter:
{
"compilerOptions": {
"module": "commonjs"
}
}
See the link above for a more complete example of a tsconfig.json file.
You have to say that to compiler, for example in npm
Option:
-m, --module Specify module code generation: 'commonjs' or 'amd'
Example:
tsc.compile(['test/cases/ship.ts', 'test/cases/fleet.ts'],
'-m commonjs -t ES5 --out test/tmp/navy.js');
for more refer to: TypeScript compiler
also have a look at this video: TypeScript Modules Demystified : Internal, AMD with RequireJS, CommonJS with NodeJS