Skip to content

tsc has "module" default to "es2015", but ts-loader does not #570

@Venryx

Description

@Venryx

Title basically says it all.

Here is my config:

{
	"compilerOptions": {
		"sourceMap": true,
		"watch": true,
		"outDir": "Source_JS",
		"forceConsistentCasingInFileNames": true,



		// this is the important line
		"module": "es2015",



		"moduleResolution": "node",
		"rootDir": "Source",
		"baseUrl": "Source",
		"paths": {
			"*": [
				"../node_modules/@types/*",
				"*"
			]
		},
		"target": "esnext",
		"lib": [
			"es6",
			"es5",
			"dom"
		],
		"allowJs": true,
		"jsx": "react",
		"noImplicitAny": false,
		"experimentalDecorators": true,
		"allowSyntheticDefaultImports": true
	},
	"files": ["Source/Main.ts"],
	"include": [
		"Typings/**/*.d.ts",
		"Source/**/*.ts",
		"Source/**/*.tsx"
	],
	"exclude": [
		"Build",
		"Tests",
		"node_modules"
	],
	"compileOnSave": true
}

I had to add the module: "es2015" line, because the handling was different between tsc and ts-loader, and it was causing problems in my project.

It was confusing because I expected an identical config file to give the same results in both tsc and ts-loader.

For reference, the difference in output between ts-loader and tsc when the "module" config was not specified, is that tsc would (correctly) output:

var _ajv = __webpack_require__(614);
var _ajv2 = _interopRequireDefault(_ajv);
var instance = new _ajv2.default();

Whereas ts-loader would output:

var _ajv = __webpack_require__(651);
var instance = new _ajv.default();

The first output is correct since "babel-plugin-transform-es2015-modules-commonjs" with default settings is enabled in the project.

I believe this can be fixed by just having the default value for "module" match that of tsc (by being "es2015"), for when it's not specified in tsconfig.json (as was the case in my project).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions