Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Requiring unknown module 'timers' #301

Open
RezaRahmati opened this issue May 16, 2016 · 19 comments
Open

Requiring unknown module 'timers' #301

RezaRahmati opened this issue May 16, 2016 · 19 comments

Comments

@RezaRahmati
Copy link

It seems that project is dependents on 'timers', but it's not added in the package.json

@Leonidas-from-XIV
Copy link
Owner

Leonidas-from-XIV commented May 16, 2016 via email

@RezaRahmati
Copy link
Author

Thanks for fast response, I use it in React-Native project, so can you give me a clue why I get this error?

@RezaRahmati
Copy link
Author

FYI, I added
"timers": "^0.1.1",
to dependencies in package.json and npm install again, it works fine

@Leonidas-from-XIV
Copy link
Owner

Leonidas-from-XIV commented May 16, 2016 via email

@davcs86
Copy link

davcs86 commented Jun 29, 2016

It's timers-browserify

@mboughaba
Copy link
Contributor

Hi,

Still facing this issue:

ERROR in ./node_modules/xml2js/lib/parser.js
Module not found: Error: Can't resolve 'timers' in 'somepath\node_modules\xml2js\lib'

and

WARNING in ./node_modules/sax/lib/sax.js
Module not found: Error: Can't resolve 'stream' in 'somepath\node_modules\sax\lib'

Adding both dependencies solves the issues but I don't think this is the way it should be handled.

@Leonidas-from-XIV
Copy link
Owner

Are you running it in a non-node environment or something?

@mboughaba
Copy link
Contributor

I am running it in an Angular project on windows.
Both dependencies were resolved before by some other dependencies in Angular itself. So they were found under ./node_modules. Now that I upgraded Angular I started getting those errors.

@Leonidas-from-XIV
Copy link
Owner

Then you probably do need these timers emulation dependencies if you're running the code in the browser.

@mboughaba
Copy link
Contributor

Great, Thank you for the confirmation. Will it help if we add those as peer dependencies? this way one would get a warning about it.

@Leonidas-from-XIV
Copy link
Owner

Hmm, maybe I am misunderstanding how that would work, but to me it doesn't look like setting them as peer dependencies will solve the issue.

Another solution would be to publish an angular-xml2js package which depends on node-xml2js and one of the timers modules.

@mboughaba
Copy link
Contributor

mboughaba commented May 26, 2018

Yes, that is a better solution. However angular-xml2js will need to be maintained separately.
@Leonidas-from-XIV I created browser-xml2js as suggested. Now I need to publish an npm package and keep it updated with this repository 🥂

Cheers

@krojew
Copy link

krojew commented Mar 7, 2019

Since angular explicitly disables default node modules, the build will break on them.

@mboughaba
Copy link
Contributor

@krojew what do you mean?
I use this and browser-xml2js in angular and build is fine

@krojew
Copy link

krojew commented Mar 7, 2019

If you don't use the browser version, it tries to use node modules which angular disabled during building. Also, browser-xml2js needs setImmediate at runtime function which doesn't exist and results in an error.

@Bi11
Copy link

Bi11 commented Apr 3, 2019

For Angular in-browser usage, add path mapping in your tsconfig.json:

  "compilerOptions": {
    "paths": {
      "timers": [
        "node_modules/timers-browserify"
      ],
      "stream": [
        "node_modules/stream-browserify"
      ],
    }
  }

A similar issue was discussed in angular-cli:
angular/angular-cli#10694 (comment)

For browser-specific shims or mocks, see https://github.com/webpack/node-libs-browser or https://github.com/browserify/browserify#compatibility .

@laurent22
Copy link

I think "timers" should be part of the dependencies. On environments that don't need it it will do nothing, and on those that miss it it will fix the issue.

@Ckm54
Copy link

Ckm54 commented Mar 17, 2023

seems there's an issue with xml2js in react native with expo keeps throwing the error and on installing module "timers" results in an app not initialized error just found another package x2js which is more recent, works without any issue and best case is written in typescript

@adam-b-jones
Copy link

seems there's an issue with xml2js in react native with expo keeps throwing the error and on installing module "timers" results in an app not initialized error just found another package x2js which is more recent, works without any issue and best case is written in typescript

THANK YOU, this fixed the problem for me! Had to replace all references to xml2js in xml.js with x2js and azure/storage-blob no longer breaks my project!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

9 participants