Skip to content

import = require is silently swallowed with module: esnext #17556

Closed
@kryops

Description

@kryops

TypeScript Version: 2.4.2 / nightly (2.5.0-dev.20170801)

Code

import isUrl = require('is-url')
console.log(isUrl('http://www.foo.bar'))

tsconfig.json

{
    "compilerOptions": {
        "target": "es5",
        "module": "esnext",
        "strict": true
    }
}

Expected behavior:
Not entirely sure what is expected to happen here:

  • "module": "commonjs" emits var isUrl = require("is-url");
  • "module": "es2015" errors with index.ts(1,1): error TS1202: Import assignment cannot be used when targeting ECMAScript 2015 modules. Consider using 'im port * as ns from "mod"', 'import {a} from "mod"', 'import d from "mod"', or another module format instead.

Actual behavior:
The compilation finishes without an error, but the import is missing in the output:

"use strict";
console.log(isUrl('http://www.foo.bar'));

Metadata

Metadata

Assignees

Labels

BugA bug in TypeScriptFixedA PR has been merged for this issueGood First IssueWell scoped, documented and has the green lightHelp WantedYou can do this

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions