Import assignment cannot be used when targeting ECMAScript 2015 modules

后端 未结 7 806
谎友^
谎友^ 2021-02-05 01:14

I\'m trying to use the follwing line:

import Clipboard = require(\'clipboard\');

and I get the following error:

   [default] c:         


        
相关标签:
7条回答
  • Try to set module as commonjs in tsconfig

    You can try this example using webpack here

    0 讨论(0)
  • 2021-02-05 01:29

    I had the same problem and changing to:

    import * as myGlobals from "../globals";
    

    fixed the problem. globals.ts file is in the main app folder, and I'm loading it up from subfolder services.

    0 讨论(0)
  • 2021-02-05 01:29

    I used default member of imported function.

    import {default as Clipboard} from 'clipboard';
    
    0 讨论(0)
  • 2021-02-05 01:31

    I was facing the same issue as you.

    In the tsconfig.json file I replaced:

    "module": "es6"
    

    with

    "module": "commonjs"
    

    and restarted the terminal. It worked.

    0 讨论(0)
  • 2021-02-05 01:41

    I had the same problem after updating my vsCode.

    just replace with "module": "es5"

    to "module": "commonjs" in tsconfig.app.json

    0 讨论(0)
  • 2021-02-05 01:41

    Similar to KristianC, I got this warning for lodash on upgrade to Angular 11

    const cloneDeep = require('lodash-es/cloneDeep');
    

    "Import assignment cannot be used when targeting ECMAScript modules."

    Warning resolved on updating "require" to "import"

    import { cloneDeep } from 'lodash-es';
    
    0 讨论(0)
提交回复
热议问题