rx-queue icon indicating copy to clipboard operation
rx-queue copied to clipboard

Bundle Error

Open CanKattwinkel opened this issue 6 years ago • 9 comments

Hello,

I tried to use your lib in an Angular project. Sadly it doesn't work due to some build error.


ERROR in ./node_modules/rx-queue/bundles/rx-queue.umd.js
Module not found: Error: Can't resolve '../../package.json' in '~/queue-error/node_modules/rx-queue/bundles'

Steps to reproduce:

  1. Create a new Angular project with @angular/cli ng new queue-error
  2. cd queue-error
  3. Install Rx-Queue: yarn add rx-queue
  4. Copy code to the app.component.ts:
import { Component } from '@angular/core';

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css']
})
export class AppComponent {
  title = 'queue-error';

  ngOnInit() {
    const queue = new RxQueue()
    queue.next(1)
    queue.next(2)
    queue.next(3)

    queue.subscribe(console.log);
  }

}
  1. start appliaction: yarn start

Or use my reproduction repo: https://github.com/CanKattwinkel/rx-queue-issue

  1. yarn install
  2. yarn start
  3. Now you get the error.

CanKattwinkel avatar Aug 08 '18 08:08 CanKattwinkel

It's great to see my rx-queue has been used in your Angular project!

This issue was caused by we try to get the npm version from the package.json, but we have only used it in the node.js environment before, and in the Angular bundle environment, there's no package.json at all, because the code was bundled.

I had just added a commit to fix this, please try the latest version v 0.4.28, and let me know if this issue was fixed.

Thanks for reporting this, have a good day!

huan avatar Aug 08 '18 16:08 huan

It still happens in 0.4.28.

asimonf avatar Sep 13 '18 13:09 asimonf

How did this happen?

We had already catch all exceptions:

https://github.com/zixia/rx-queue/blob/8179faa5443c57b331f72e4a04a6fc5af6524cc3/src/config.ts#L1-L11

huan avatar Sep 13 '18 14:09 huan

I'm having the same problem with Angular 6 as well.

As far as I can tell, the VERSION (and corresponding version() function) aren't actually used for anything. Once I removed the VERSION grabbing stuff locally the package still worked without issue.

footballencarta avatar Sep 14 '18 15:09 footballencarta

Will try this module: https://github.com/rollup/rollup-plugin-json

huan avatar Sep 16 '18 16:09 huan

@zixia

Why does the version needs to be part of the bundle? If anyone is interested in the version he/she would require the package.json file from the node_modules folder.

CanKattwinkel avatar Sep 16 '18 16:09 CanKattwinkel

@CanKattwinkel The version needs to be part of the bundle because I want to get the version from the instance.

This issue should have been fixed from [email protected] or above, please feel free to let me know if there still have any problems.

huan avatar Sep 16 '18 17:09 huan

@zixia I agree with @CanKattwinkel - there's no actual need for returning the actual version number from the package. This is the first and only package I've ever come across that does it, and it's the only one that has this particular problem - so the two are definitely related.

What does it do? It returns the version of the package

Why? Because we want to run it in smoke tests to check the package has loaded correctly.

What problem is it causing? In Angular 6+ (which quite a lot of people will be using this with) it errors that the package.json cannot be found, leading to runtime errors (not compile time).

How can this be fixed? The easiest way to fix this is to return a static value from the existing function as not to break backwards compatibility.

This was the thinking behind the pull request that's now been closed (because you've done all the work yourself anyway, rendering it moot) - and I believe your approach to this problem is incorrect.

footballencarta avatar Sep 17 '18 07:09 footballencarta

@footballencarta thank you for your pull request and sharing your thinking behind the PR.

As I said in reply to your PR, we need to keep it working by fix the problem under angular 6 instead of hard coded the version number inside the source code.

From [email protected], the rollup will get the version number from the package.json to the bundle automatically, just like what your PR does.

huan avatar Sep 17 '18 08:09 huan