Quantcast
Channel: Active questions tagged visual-studio-code - Stack Overflow
Viewing all articles
Browse latest Browse all 99653

How to use 'require' instead of 'import' statements

$
0
0

In JavaScript, node.js, when I export module using CommonJS style, such as

module.export.foo = (param) => {
    // do sth here
   return value
}

and I start typing foo in the other file in my node.js project, VS Code suggests: "Auto import from 'path/to/file'" after pressing enter, VS Code inserts statement at the top of the file:

import { foo } from 'path/to/file'

I'd like VS code to paste following code instead:

const { foo } = require('path/to/file')

Is it possible?

My jsconfig.json looks like that:

{
    "compilerOptions": {
      "module": "commonjs",
      "target": "es6"
    },
    "include": [
        "src/**/*",
        "__tests__/**/*"
    ]
  }

Viewing all articles
Browse latest Browse all 99653


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>