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.

Compiling Angular code with nats.ws as dependency fails

See original GitHub issue

Hi there,

first of all, thank you for your work. This repo helped us a lot.

Currently, we are using an older version of nats.ws, and when trying to update to nats.ws 1.0.0-117, we encounter a few compilation errors, such as:

Error: ./node_modules/nats.ws/nats.mjs 1070:22
Module parse failed: Unexpected token (1070:22)
You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders
|         this._off = 0;
|     }
>     _tryGrowByReslice = (n)=>{
|         const l = this._buf.byteLength;
|         if (n <= this.capacity - l) {
 @ ./src/app/app.component.ts 2:0-34 40:8-15
 @ ./src/app/app.module.ts
 @ ./src/main.ts
 @ multi ./src/main.ts

This is a log from trying to compile this example repo I set up, but it’s the same log in our main application.

The example repo uses Angular 11, we currently use Angular 10.

If I follow the errors and fix them, the code works, but this is not a good solution because we would need to copy the code from the dependency into our own repository and keep making the same modifications for all upcoming updates.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:5
  • Comments:16 (12 by maintainers)

github_iconTop GitHub Comments

2reactions
cuddlecakecommented, Feb 1, 2021

Hi @aricart, could you perhaps release a new version of this lib?

1reaction
cuddlecakecommented, Feb 9, 2021

It compiles now, but it’s still awkward to consume.

To the Angular users:

If you are using Jest for testing, you will run into another rabbit hole because of *.mjs. For now, I solves this by adding a nats.mock.ts file somewhere, with the content:

// nats.mock.ts

export const connect = jest.fn();

with usage in a test suite:

// socket.service.spec.ts
// Note that, even if you don't use it in tests, any test that indirectly imports `nats.ws` will break.

describe('My Socket Service', () => {
    connectMock = <jest.Mock>nats.connect;
    beforeEach(() => {
        connectMock.mockReset();
    })
})

and the addition to jest.config.js:

module.exports = {
    // ... other config
    transform: {
        // I think this should already be included if you are using jest for Angular
        '^.+\\.(ts|html)$': 'ts-jest',
    },
    moduleNameMapper: {
        // note that the file ending here is `.js`, not `.ts`, probably because of ts-jest
        'nats.ws': 'path/to/nats.mock.js',
    }
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

nats.ws - npm
nats.ws is an async nats client. The model a standard ES Module. Copy the nats.js module from node_modules (if you didn't build it...
Read more >
Typescript NATS | NATS blog - NATS.io
With TypeScript we can write better JavaScript: Tooling helps us write correct code; refactoring code is possible and safer, and compiler ...
Read more >
Identify and Fix Build and Deployment Errors in Your Angular ...
In this guide, you will learn how to spot some of the most common build and deployment errors and how to resolve them...
Read more >
Module not found: Error: Can't resolve 'util' in webpack
Ejecting the entire Angular build system just to fix a dependency is insane. – Askdesigners. May 23, 2022 at 7:49. I don' ...
Read more >
Compare Packages Between Distributions - DistroWatch.com
Algorithm-Dependency 1.112.0. Algorithm-Diff 1.201.0 ... Apache-LogFormat-Compiler 0.360.0 apache-mode 2.2.0 ... kdsoap-ws-discovery-client 0.2_pre20200927
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