I prefer using the import x from 'y' syntax, but all I've seen online is const path = require('path').
Is there a way to import the path module using this syntax?
For people trying to import path in a TypeScript file, and ending up here:
Be sure to have node types installed:
npm install --save-dev @types/node
Import path symbol:
import * as path from 'path';
Note: @types/* are automatically included for compilation, providing you use typescript version 2.0 or above, and provided you don't override the types property in compiler options file (tsconfig.json).
You can either do
import module from 'path'
or if you just need to import path just do
import 'path'
If not using typescript
import * as path from 'path'
is the only thing that works for me.
import path from 'path';
As of now, this is the code that's working for me in typescript.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With