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.

Fails to build in nodejs environment

See original GitHub issue

Hi! I’m trying to use this library with firebase functions (node 12 environment), but I’m getting a build error from tsc.

It’s a newly create firebase functions project (so fairly standard settings). This is my tsconfig file:

{
  "compilerOptions": {
    "module": "commonjs",
    "noImplicitReturns": true,
    "noUnusedLocals": true,
    "outDir": "lib",
    "sourceMap": true,
    "strict": true,
    "target": "es2017",
    "typeRoots": ["node_modules/@types"]
  },
  "compileOnSave": true,
  "include": [
    "src"
  ]
}

This is the output:


node_modules/@master-chief/alpaca/@types/stream.d.ts:1:23 - error TS2688: Cannot find type definition file for 'ws'.

1 /// <reference types="ws" />
                        ~~

node_modules/@master-chief/alpaca/@types/stream.d.ts:2:8 - error TS1259: Module '"/Users/fredrik/github/garagefunds/functions/node_modules/isomorphic-ws/index"' can only be default-imported using the 'esModuleInterop' flag

2 import WebSocket from 'isomorphic-ws';
         ~~~~~~~~~

  node_modules/isomorphic-ws/index.d.ts:8:1
    8 export = WebSocket
      ~~~~~~~~~~~~~~~~~~
    This module is declared with using 'export =', and can only be used with a default import when using the 'esModuleInterop' flag.

node_modules/@master-chief/alpaca/@types/stream.d.ts:3:8 - error TS1259: Module '"/Users/fredrik/github/garagefunds/functions/node_modules/eventemitter3/index"' can only be default-imported using the 'esModuleInterop' flag

3 import EventEmitter from 'eventemitter3';
         ~~~~~~~~~~~~

  node_modules/eventemitter3/index.d.ts:134:1
    134 export = EventEmitter;
        ~~~~~~~~~~~~~~~~~~~~~~
    This module is declared with using 'export =', and can only be used with a default import when using the 'esModuleInterop' flag.

node_modules/isomorphic-ws/index.d.ts:6:28 - error TS7016: Could not find a declaration file for module 'ws'. '/Users/fredrik/github/garagefunds/functions/node_modules/ws/index.js' implicitly has an 'any' type.
  Try `npm install @types/ws` if it exists or add a new declaration (.d.ts) file containing `declare module 'ws';`

6 import WebSocket = require('ws')
                             ~~~~


Found 4 errors.

Any idea what this might be about?

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
FredrikNorencommented, Mar 15, 2021

@117 Doh, yeah installing ws types solved it! Should have tried it but I just assumed they were already included. Thanks!

0reactions
husaytcommented, Mar 15, 2021

@117 I don’t think there is something to fix on our side. I have a typescript project which works just fine. It has to be smth with the way project configured.

Here is a sample tsconfig, which works for me:

{
  "compilerOptions": {
    "baseUrl": ".",
    "module": "ESNext",
    "target": "es2016",
    "lib": ["DOM", "ESNext"],
    "strict": true,
    "esModuleInterop": true,
    "incremental": true,
    "skipLibCheck": true,
    "moduleResolution": "node",
    "resolveJsonModule": true,
    "noUnusedLocals": true,
    "strictNullChecks": true,
    "forceConsistentCasingInFileNames": true,
  },
  "exclude": ["node_modules"]
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

Fails to build in nodejs environment · Issue #66
Hi! I'm trying to use this library with firebase functions (node 12 environment), but I'm getting a build error from tsc.
Read more >
6 reasons your Node.js apps are failing
Can't figure out why your Node.js applications are failing? This article covers common Node failure points and the open source tools you can...
Read more >
node.js build fails if warnings present
Hi Varnav, the build is failing as warnings are being treated as errors due to a certain environment variable being set/not set. In...
Read more >
GYP ERR! build error. stack Error: 'make' failed with exit ...
I am currently working on a nodejs web application ...
Read more >
15 Common Error Codes in Node.js and How to Fix Them
15. EPERM · Close all instances of your editor before rerunning the command (maybe some files were locked by the editor). · Clean...
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