GithubHelp home page GithubHelp logo

Comments (7)

isaacs avatar isaacs commented on June 10, 2024

What build issues does it cause? Please provide reproduction, showing expectation and actual behavior.

from node-lru-cache.

JimmyBjorklund avatar JimmyBjorklund commented on June 10, 2024

We are using "coap": "^1.3.0", and when building it seams to get confused about the namespace and class. It should work just fine but for some reason it takes the namespace instead of the class.
Thay do this in there code https://github.com/coapjs/node-coap/blob/master/lib/server.ts

class CoapLRUCache<K extends {}, V extends {}> extends LRUCache<K, V> {
pruneTimer: NodeJS.Timeout
}

node_modules/coap/dist/lib/server.d.ts:11:10 - error TS2617: 'LRUCache' can only be imported by using 'import LRUCache = require("lru-cache")' or by turning on the 'esModuleInterop' flag and using a default import.

11 import { LRUCache } from 'lru-cache';

from node-lru-cache.

isaacs avatar isaacs commented on June 10, 2024

Give me some code and a command to run so that I can see it happening. LRUCache seems to build just fine in every situation I've used it, so there's something particular to either your setup or theirs, but if I can't reproduce it, I cannot help you, sorry.

from node-lru-cache.

JimmyBjorklund avatar JimmyBjorklund commented on June 10, 2024

I created a smal sample, the first error is easy to get around and thats just to add { } aroung 3 import BufferListStream from 'bl';
But the last one seams to get the compiler to go bananas, npm run start works but npm run build do not. Only thing i can think of is that its to do with the namespace and class name.
https://github.com/JimmyBjorklund/t-coap

from node-lru-cache.

isaacs avatar isaacs commented on June 10, 2024

That is not the problem.

node_modules/coap/dist/lib/server.d.ts:11:8 - error TS1259: Module '"/Users/isaacs/dev/isaacs/lru-cache/t-coap/node_modules/@types/lru-cache/index"' can only be default-imported using the 'esModuleInterop' flag

11 import LRUCache from 'lru-cache';
          ~~~~~~~~

This patch will fix the issue for you:

diff --git a/tsconfig.json b/tsconfig.json
index b1937c9..6229b40 100644
--- a/tsconfig.json
+++ b/tsconfig.json
@@ -1,6 +1,7 @@
 {
     "compileOnSave": true,
     "compilerOptions": {
+      "esModuleInterop": true,
       "allowJs": true,
       "baseUrl": ".",
       "experimentalDecorators": true,

Or, since really this is an issue with the coap lib, not your code, you could use this patch to avoid type checking code you don't own:

diff --git a/tsconfig.json b/tsconfig.json
index b1937c9..5dcef04 100644
--- a/tsconfig.json
+++ b/tsconfig.json
@@ -2,6 +2,7 @@
     "compileOnSave": true,
     "compilerOptions": {
       "allowJs": true,
+      "skipLibCheck": true,
       "baseUrl": ".",
       "experimentalDecorators": true,
       "emitDecoratorMetadata": true,

Not a problem with lru-cache.

from node-lru-cache.

isaacs avatar isaacs commented on June 10, 2024

Also, coap is using lru-cache v6 (current is v10.2.0). If they upgrade to the latest lru-cache, then they can also ditch @types/lru-cache, because the types are included.

I recommend you suggest this to them.

from node-lru-cache.

JimmyBjorklund avatar JimmyBjorklund commented on June 10, 2024

Thanks.

from node-lru-cache.

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.