Giter VIP home page Giter VIP logo

Comments (9)

JeromeDeLeon avatar JeromeDeLeon commented on May 18, 2024 5

Same here, I inserted the allowSyntheticDefaultImports and esModuleInterop but still doing import ms from 'ms' still gives me undefined when accessing it. I scaffolded the project based on the NestJS setup.

{
  "compilerOptions": {
    "module": "commonjs",
    "declaration": true,
    "removeComments": true,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "allowSyntheticDefaultImports": true,
    "esModuleInterop": true,
    "target": "es2017",
    "sourceMap": true,
    "outDir": "./dist",
    "baseUrl": "./",
    "incremental": true
  }
}
`

from ms.

stefanpl avatar stefanpl commented on May 18, 2024 4

@kingdaro thanks for your comment! I had not been aware that the import x = require syntax is non-standard, I'll try to avoid it in the future. Problem is, last time I tried esModuleInterop, it was not working very smoothly. Guess I'll have to do some digging there as well.

Is migrating the ms package to the ES module format an option? I guess that would be the gist of this ticket, wouldn't it?

from ms.

itsMapleLeaf avatar itsMapleLeaf commented on May 18, 2024 1

The import x = require('x') syntax is discouraged in use for modern code bases, since it's non-standard. Turning on esModuleInterop is the real fix here.

The module is written in CJS, so if you're using ES modules, interop is needed to import it, as a default.

from ms.

vtrphan avatar vtrphan commented on May 18, 2024 1

i'm having problem too. why closed?

from ms.

homj avatar homj commented on May 18, 2024 1

same for me!
I think this issue should be reopened

from ms.

guiseek avatar guiseek commented on May 18, 2024 1

the solution might be to install the canary version, like this:
npm i [email protected]

and import as follows:
import ms, { StringValue } from 'ms'

are now using string types, the code would look like this:

export class DateInterval {
   public readonly ms: number;

   constructor(interval: StringValue) {
     this.ms = ms(interval);
   }
}

from ms.

stefanpl avatar stefanpl commented on May 18, 2024

@Baterka you can import (without the esModuleInterop flag) by using this syntax:

import ms = require('ms');

from ms.

Baterka avatar Baterka commented on May 18, 2024

Why closed?

from ms.

guiseek avatar guiseek commented on May 18, 2024

https://www.npmjs.com/package/@types/ms

is this library already typescript in your source? why are you still maintaining the @types/ms project? there should be a notice there stating that it's no longer needed, no?

from ms.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.