node-xml2js
node-xml2js copied to clipboard
Requiring unknown module 'timers'
It seems that project is dependents on 'timers', but it's not added in the package.json
That module is part of Nodejs.
Thanks for fast response, I use it in React-Native project, so can you give me a clue why I get this error?
FYI, I added
"timers": "^0.1.1",
to dependencies in package.json and npm install
again, it works fine
That's odd, that module does not seem to have any setImmediate
function, which is the only one required by xml2js.
It's timers-browserify
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.
Are you running it in a non-node environment or something?
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.
Then you probably do need these timers
emulation dependencies if you're running the code in the browser.
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.
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.
~~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
Since angular explicitly disables default node modules, the build will break on them.
@krojew what do you mean? I use this and browser-xml2js in angular and build is fine
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.
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: https://github.com/angular/angular-cli/issues/10694#issuecomment-428520833
For browser-specific shims or mocks, see https://github.com/webpack/node-libs-browser or https://github.com/browserify/browserify#compatibility .
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.
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
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 packagex2js
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!