Comments (7)
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.
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.
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.
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.
close it, I assume you solved this problem.
Feel free to reopen it if you have any further questions.
from truncate-html.
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.
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)
- Truncate by word count instead of length HOT 7
- Causes serious issue relating to unknown module "events" with NativeScript HOT 3
- Reuse existing cheerio instance, avoid reparsing HOT 3
- TypeError: $ is not a function HOT 1
- Perversing the last word for a single word over the character limit HOT 10
- Different behaviour when text is exactly at limit vs over limit when preversing last word HOT 1
- Option to not remove extra white spaces HOT 5
- Missing 'load' export in the embedded cheerio dependency HOT 1
- High vulnerabie dependency found when installing the package HOT 8
- Cannot find name 'CheerioStatic'. HOT 1
- Typo in distributed version HOT 1
- Depedency vulnerabilities HOT 1
- Console.logs HOT 2
- No ellipses if truncated on tag boundary HOT 1
- stripTags: true does not strip tags HOT 3
- Feature request: add option to truncate at word boundary HOT 2
- Option for add space after end of tag HOT 2
- Upgrade Cheerio to 0.22.0
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from truncate-html.