Giter Club home page Giter Club logo

Comments (7)

oe avatar oe commented on August 25, 2024

This lib should be import via the second way. I run test this lib from scratch, just found that, you may need to update your tsconfig.json by adding "esModuleInterop": true to the compilerOptions.

check Typescript 2.7(just search esModuleInterop) for more details.

Here is the complete tsconfig.json I used to test for you to refer.

{
  "compilerOptions": {
    "sourceMap": true,
    "strict": true,
    "noImplicitReturns": true,
    "target": "es6",
    "module": "commonjs",
    "moduleResolution": "node",
    "lib": ["es7"],
    "experimentalDecorators": true,
    "emitDecoratorMetadata": false,
    "allowSyntheticDefaultImports": true,
    "suppressImplicitAnyIndexErrors": true,
    "strictFunctionTypes": false,
    "esModuleInterop": true,
    "allowJs": true,
    "baseUrl": "."
  },
  "exclude": ["node_modules"]
}

from truncate-html.

oe avatar oe commented on August 25, 2024

This lib exports both commonjs and es6 files, but commonjs file will be required by default , So you may need to add this option"esModuleInterop": true if your building tools don't support es6 module.

https://github.com/evecalm/truncate-html/blob/master/package.json#L5-L7

from truncate-html.

wujekbogdan avatar wujekbogdan commented on August 25, 2024

Setting esModuleInterop to true solves the problem, but it also breaks other modules' imports. For example: days. I used to import it like import * as dayjs from "dayjs";, now I have to import it like import dayjs from "dayjs";. It happens because when esModuleInterop is set to true then it enables allowSyntheticDefaultImports under the hood.

From docs:

Emit __importStar and __importDefault helpers for runtime babel ecosystem compatibility and enable --allowSyntheticDefaultImports for typesystem compatibility.

from truncate-html.

oe avatar oe commented on August 25, 2024

I'm a little confused, if set allowSyntheticDefaultImports to true, you will be able to keep using this style import * as dayjs from "dayjs"

check the code of this lib:

https://github.com/evecalm/truncate-html/blob/master/src/truncate.ts#L1

https://github.com/evecalm/truncate-html/blob/master/tsconfig.json#L2-L19

from truncate-html.

oe avatar oe commented on August 25, 2024

close it, I assume you solved this problem.

Feel free to reopen it if you have any further questions.

from truncate-html.

wujekbogdan avatar wujekbogdan commented on August 25, 2024

@evecalm

I solved the problem differently. I use const truncate = require("truncate-html"); as a workaround to import the module because I don't want to change tsconfig settings. Such a change would affect all my existing codebase. The dayjs module is not the only one that would be affected. I gave it just an example.

from truncate-html.

oe avatar oe commented on August 25, 2024

It should works in my way.

You may try it your self by following steps:

git clone https://github.com/evecalm/truncate-html.git
cd truncate-html
yarn add dayjs

then edit test/demo.ts by adding code:

import dayjs from 'dayjs'
console.log('test dayjs', dayjs.isDayjs())

run the code to test: yarn run dev

from truncate-html.

Related Issues (19)

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.