question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

.extend() not working with ES6's import statement

See original GitHub issue

Sorry if this has already been asked, but I couldn’t find the answer anywhere.

Basically, doing this works:

import nlp from 'compromise'

This too:

const nlp = require('compromise')
nlp.extend(require('compromise-ngrams'))

But this:

import nlp from 'compromise
nlp.extend(require('compromise-ngrams'))

Makes TSLint throw this error:

Property ‘ngrams’ does not exist on type ‘DefaultDocument’.

What’s the proper way of extending Compromise in an ES6 way?

Note: This is my tsconfig:

"compilerOptions": {
  "module": "commonjs",
  "target": "es6",
  "outDir": "out",
  "sourceMap": true,
  "rootDir": "src",
  "strict": true,
  "esModuleInterop": true // this makes my first example work
},

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
Drache93commented, Feb 6, 2020

Thanks, for the feedback - will make a PR with updated Readme. So far the readme doesn’t include typescript specific stuff.

0reactions
alexcheninfocommented, Feb 6, 2020

That did it. Thanks! Your suggestion worked even without the compromise-numbers package.

Seems like if you want to use import, you have to do const nlpEx = nlp.extend(extension_name).

I’m glad you’re replying to these questions. The information you provide isn’t on the net, I think.

(And thanks, I didn’t know you could drop images here!)

Read more comments on GitHub >

github_iconTop Results From Across the Web

ES6 importing extended classes - javascript - Stack Overflow
I think the problem is that the Posts class is not being moved with the MyClass class; but without casting I have no...
Read more >
Solved: How to import a javascript class and extend it in
Solved: Hi I am trying to use two Javascript projects - and export a class defined in one to be extended (inherited) in...
Read more >
Extending a list in Python (5 different ways) - GeeksforGeeks
Let's see all of them one by one. 1. Using append() function: We can append at the end of the list by using...
Read more >
can not use import statement outside a module - YouTube
Join this channel to get access to perks:https://www.youtube.com/channel/UCoSpmr2KNOxjwE_B9ynUmig/joinMy GearCamera ...
Read more >
Python List extend() Method - W3Schools
The extend() method adds the specified list elements (or any iterable) to the end of the current list. Syntax. list.extend(iterable). Parameter Values ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found