Skip to content

Error when using dynamic import -- support esnext #54

@RiftLurker

Description

@RiftLurker

What happens and why it is wrong

When using dynamic imports the following error is thrown:

[!] (rpt2 plugin) Error: /home/leo/development/other/rollup-plugin-typescript2-debug/a.ts(1,1): semantic error TS1323 Dynamic import cannot be used when targeting ECMAScript 2015 modules.
a.ts
Error: /home/leo/development/other/rollup-plugin-typescript2-debug/a.ts(1,1): semantic error TS1323 Dynamic import cannot be used when targeting ECMAScript 2015 modules.
    at error (/home/leo/development/other/rollup-plugin-typescript2-debug/node_modules/rollup/dist/rollup.js:170:15)
    at /home/leo/development/other/rollup-plugin-typescript2-debug/node_modules/rollup/dist/rollup.js:17346:17
    at <anonymous>
    at process._tickCallback (internal/process/next_tick.js:188:7)
    at Function.Module.runMain (module.js:667:11)
    at startup (bootstrap_node.js:187:16)
    at bootstrap_node.js:607:3

This is caused by this module forcefully setting the module compiler option to es2015.

Environment

a.ts

import('./b').then(({ message }) => console.log(message));

b.ts

export const message = 'it works!';

Versions

  • typescript: 2.6.2
  • rollup: 0.53.4
  • rollup-plugin-typescript2: 0.9.0

rollup.config.js

"use strict";

import typescript from "rollup-plugin-typescript2";

export default {
  input: "./a.ts",
  output: {
    format: "cjs",
  },

  plugins: [
    typescript({
      tsconfig: './tsconfig.json',
      verbosity: 3,
    })
  ]
}

tsconfig.json

{
  "compilerOptions": {
    "module": "commonjs",
    "target": "es2015"
  }
}

plugin output with verbosity 3

rpt2: typescript version: 2.8.0-dev.20180131
rpt2: rollup-plugin-typescript2 version: 0.9.0
rpt2: plugin options:
{
    "tsconfig": "./tsconfig.json",
    "verbosity": 3,
    "check": true,
    "clean": false,
    "cacheRoot": "/home/leo/development/other/rollup-plugin-typescript2-debug/.rpt2_cache",
    "include": [
        "*.ts+(|x)",
        "**/*.ts+(|x)"
    ],
    "exclude": [
        "*.d.ts",
        "**/*.d.ts"
    ],
    "abortOnError": true,
    "rollupCommonJSResolveHack": false,
    "useTsconfigDeclarationDir": false,
    "typescript": "version 2.8.0-dev.20180131",
    "tsconfigOverride": {}
}
rpt2: rollup config:
{
    "input": "./a.ts",
    "plugins": [
        {
            "name": "rpt2"
        }
    ],
    "entry": "./a.ts",
    "external": [
        "",
        ""
    ]
}
rpt2: built-in options overrides: {
    "module": 5,
    "noEmitHelpers": true,
    "importHelpers": true,
    "noResolve": false,
    "noEmit": false,
    "outDir": "/home/leo/development/other/rollup-plugin-typescript2-debug",
    "moduleResolution": 2
}
rpt2: parsed tsconfig: {
    "options": {
        "module": 5,
        "target": 2,
        "outDir": "/home/leo/development/other/rollup-plugin-typescript2-debug",
        "baseUrl": "/home/leo/development/other/rollup-plugin-typescript2-debug/src/",
        "sourceMap": true,
        "strict": true,
        "experimentalDecorators": true,
        "noImplicitReturns": true,
        "allowSyntheticDefaultImports": true,
        "allowUnreachableCode": false,
        "noEmitHelpers": true,
        "importHelpers": true,
        "noResolve": false,
        "noEmit": false,
        "moduleResolution": 2,
        "configFilePath": "/home/leo/development/other/rollup-plugin-typescript2-debug/./tsconfig.json"
    },
    "fileNames": [
        "/home/leo/development/other/rollup-plugin-typescript2-debug/a.ts",
        "/home/leo/development/other/rollup-plugin-typescript2-debug/b.ts",
        "/home/leo/development/other/rollup-plugin-typescript2-debug/src/a.ts",
        "/home/leo/development/other/rollup-plugin-typescript2-debug/src/main.ts",
        "/home/leo/development/other/rollup-plugin-typescript2-debug/src/types.d.ts",
        "/home/leo/development/other/rollup-plugin-typescript2-debug/src/utils/ErrorMapper.ts"
    ],
    "typeAcquisition": {
        "enable": false,
        "include": [],
        "exclude": []
    },
    "raw": {
        "compilerOptions": {
            "module": "commonjs",
            "target": "es2015",
            "outDir": "dist",
            "baseUrl": "src/",
            "sourceMap": true,
            "strict": true,
            "experimentalDecorators": true,
            "noImplicitReturns": true,
            "allowSyntheticDefaultImports": true,
            "allowUnreachableCode": false
        },
        "exclude": [
            "node_modules"
        ]
    },
    "errors": [],
    "wildcardDirectories": {
        "/home/leo/development/other/rollup-plugin-typescript2-debug": 1
    },
    "compileOnSave": false,
    "configFileSpecs": {
        "includeSpecs": [
            "**/*"
        ],
        "excludeSpecs": [
            "node_modules"
        ],
        "validatedIncludeSpecs": [
            "**/*"
        ],
        "validatedExcludeSpecs": [
            "node_modules"
        ],
        "wildcardDirectories": {
            "/home/leo/development/other/rollup-plugin-typescript2-debug": 1
        }
    }
}
rpt2: included:
'[
    "*.ts+(|x)",
    "**/*.ts+(|x)"
]'
rpt2: excluded:
'[
    "*.d.ts",
    "**/*.d.ts"
]'
rpt2: Ambient types:
rpt2:     /home/leo/development/other/rollup-plugin-typescript2-debug/src/types.d.ts
rpt2:     /home/leo/development/other/rollup-plugin-typescript2-debug/node_modules/@types/lodash/index.d.ts
rpt2:     /home/leo/development/other/rollup-plugin-typescript2-debug/node_modules/@types/node/index.d.ts
rpt2:     /home/leo/development/other/rollup-plugin-typescript2-debug/node_modules/@types/screeps/index.d.ts
rpt2: ambient types changed, redoing all semantic diagnostics
rpt2: transpiling '/home/leo/development/other/rollup-plugin-typescript2-debug/a.ts'
rpt2:     cache: '/home/leo/development/other/rollup-plugin-typescript2-debug/.rpt2_cache/cd81cf42f3dcf638d9c3e61868cbf69ad7637cd0/code/cache/f11ac0bffbde51209d9a516866cafbe3aca2435c'
rpt2:     cache miss
rpt2:     cache: '/home/leo/development/other/rollup-plugin-typescript2-debug/.rpt2_cache/cd81cf42f3dcf638d9c3e61868cbf69ad7637cd0/syntacticDiagnostics/cache/f11ac0bffbde51209d9a516866cafbe3aca2435c'
rpt2:     cache miss
rpt2:     cache: '/home/leo/development/other/rollup-plugin-typescript2-debug/.rpt2_cache/cd81cf42f3dcf638d9c3e61868cbf69ad7637cd0/semanticDiagnostics/cache/f11ac0bffbde51209d9a516866cafbe3aca2435c'
rpt2:     cache miss
[!] (rpt2 plugin) Error: /home/leo/development/other/rollup-plugin-typescript2-debug/a.ts(1,1): semantic error TS1323 Dynamic import cannot be used when targeting ECMAScript 2015 modules.
a.ts
Error: /home/leo/development/other/rollup-plugin-typescript2-debug/a.ts(1,1): semantic error TS1323 Dynamic import cannot be used when targeting ECMAScript 2015 modules.
    at error (/home/leo/development/other/rollup-plugin-typescript2-debug/node_modules/rollup/dist/rollup.js:170:15)
    at /home/leo/development/other/rollup-plugin-typescript2-debug/node_modules/rollup/dist/rollup.js:17346:17
    at <anonymous>
    at process._tickCallback (internal/process/next_tick.js:188:7)
    at Function.Module.runMain (module.js:667:11)
    at startup (bootstrap_node.js:187:16)
    at bootstrap_node.js:607:3

Metadata

Metadata

Assignees

Labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions