Leonidas-from-XIV / node-xml2js

XML to JavaScript object converter.
MIT License
4.88k stars 602 forks source link

Unable to resolve module 'events' #363

Open joetidee opened 7 years ago

joetidee commented 7 years ago

After requiring this package as per the instructions, I am getting:

Unable to resolve module 'events' from '/Users/myName/AwesomeProject/node_modules: Module does not exist in the module map ...

Leonidas-from-XIV commented 7 years ago

How did you install xml2js?

i8wu commented 7 years ago

Just installed using npm, getting the same error.

Edit: Resolved after npm install events and timers, but I think those two should be listed as dependencies for xml2js?

ipoweb commented 7 years ago

i have the same problem with angular2, i did this:

npm install @types/xml2js --save-dev npm install xml2js --save-dev npm install events --save-dev

then i can build, but i not tested if it'w work. Why i8wu you need timers ?

i8wu commented 7 years ago

@sireneweb it came up as an unable to resolve module npm install timers

agersoncgps commented 7 years ago

I am getting this for every dependency, streams, buffers, timers...

Leonidas-from-XIV commented 7 years ago

Can you post your entire stdout?

agersoncgps commented 7 years ago
Last login: Thu Jul 27 18:32:12 on ttys003
Adams-iMac-3:~ agerson$ cd /Users/agerson/Desktop/CGPSApp 
Adams-iMac-3:CGPSApp agerson$ npm install xml2js --save --loglevel verbose
npm info it worked if it ends with ok
npm verb cli [ '/usr/local/bin/node',
npm verb cli   '/usr/local/bin/npm',
npm verb cli   'install',
npm verb cli   'xml2js',
npm verb cli   '--save',
npm verb cli   '--loglevel',
npm verb cli   'verbose' ]
npm info using npm@3.10.10
npm info using node@v6.11.1
npm verb request uri https://registry.npmjs.org/xml2js
npm verb request no auth needed
npm info attempt registry request try #1 at 8:32:14 PM
npm verb request id 05644741b37650bb
npm verb etag W/"5978142e-1ebbc"
npm verb lastModified Wed, 26 Jul 2017 04:01:50 GMT
npm http request GET https://registry.npmjs.org/xml2js
npm http 304 https://registry.npmjs.org/xml2js
npm verb headers { date: 'Fri, 28 Jul 2017 00:32:14 GMT',
npm verb headers   via: '1.1 varnish',
npm verb headers   'cache-control': 'max-age=300',
npm verb headers   etag: 'W/"5978142e-1ebbc"',
npm verb headers   age: '273',
npm verb headers   connection: 'keep-alive',
npm verb headers   'x-served-by': 'cache-jfk8134-JFK',
npm verb headers   'x-cache': 'HIT',
npm verb headers   'x-cache-hits': '4114',
npm verb headers   'x-timer': 'S1501201935.862040,VS0,VE0',
npm verb headers   vary: 'Accept-Encoding, Accept' }
npm verb etag https://registry.npmjs.org/xml2js from cache
npm verb get saving xml2js to /Users/agerson/.npm/registry.npmjs.org/xml2js/.cache.json
npm verb correctMkdir /Users/agerson/.npm correctMkdir not in flight; initializing
npm verb cache add spec xml2js@^0.4.17
npm verb addNamed ">=0.4.17 <0.5.0" is a valid semver range for xml2js
npm verb addNameRange registry:https://registry.npmjs.org/xml2js not in flight; fetching
npm verb get https://registry.npmjs.org/xml2js not expired, no request
npm verb addNamed "0.4.17" is a plain semver version for xml2js
npm verb afterAdd /Users/agerson/.npm/xml2js/0.4.17/package/package.json not in flight; writing
npm verb correctMkdir /Users/agerson/.npm correctMkdir not in flight; initializing
npm verb afterAdd /Users/agerson/.npm/xml2js/0.4.17/package/package.json written
npm verb request uri https://registry.npmjs.org/xmlbuilder
npm verb request no auth needed
npm info attempt registry request try #1 at 8:32:15 PM
npm verb etag W/"59526267-1563d"
npm verb lastModified Tue, 27 Jun 2017 13:49:27 GMT
npm http request GET https://registry.npmjs.org/xmlbuilder
npm http 304 https://registry.npmjs.org/xmlbuilder
npm verb headers { date: 'Fri, 28 Jul 2017 00:32:15 GMT',
npm verb headers   via: '1.1 varnish',
npm verb headers   'cache-control': 'max-age=300',
npm verb headers   etag: 'W/"59526267-1563d"',
npm verb headers   age: '62',
npm verb headers   connection: 'keep-alive',
npm verb headers   'x-served-by': 'cache-jfk8134-JFK',
npm verb headers   'x-cache': 'HIT',
npm verb headers   'x-cache-hits': '1',
npm verb headers   'x-timer': 'S1501201936.700066,VS0,VE0',
npm verb headers   vary: 'Accept-Encoding, Accept' }
npm verb etag https://registry.npmjs.org/xmlbuilder from cache
npm verb get saving xmlbuilder to /Users/agerson/.npm/registry.npmjs.org/xmlbuilder/.cache.json
npm verb correctMkdir /Users/agerson/.npm correctMkdir not in flight; initializing
npm verb cache add spec xmlbuilder@^4.1.0
npm verb addNamed ">=4.1.0 <5.0.0" is a valid semver range for xmlbuilder
npm verb addNameRange registry:https://registry.npmjs.org/xmlbuilder not in flight; fetching
npm verb get https://registry.npmjs.org/xmlbuilder not expired, no request
npm verb addNamed "4.2.1" is a plain semver version for xmlbuilder
npm verb afterAdd /Users/agerson/.npm/xmlbuilder/4.2.1/package/package.json not in flight; writing
npm verb correctMkdir /Users/agerson/.npm correctMkdir not in flight; initializing
npm verb afterAdd /Users/agerson/.npm/xmlbuilder/4.2.1/package/package.json written
npm verb correctMkdir /Users/agerson/.npm/_locks correctMkdir not in flight; initializing
npm verb lock using /Users/agerson/.npm/_locks/staging-3d17163a40924b46.lock for /Users/agerson/Desktop/CGPSApp/node_modules/.staging
npm verb unbuild node_modules/.staging/xml2js-c5f46ee4
npm verb gentlyRm don't care about contents; nuking /Users/agerson/Desktop/CGPSApp/node_modules/.staging/xml2js-c5f46ee4
npm verb tar unpack /Users/agerson/.npm/xml2js/0.4.17/package.tgz
npm verb tar unpacking to /Users/agerson/Desktop/CGPSApp/node_modules/.staging/xml2js-c5f46ee4
npm verb gentlyRm don't care about contents; nuking /Users/agerson/Desktop/CGPSApp/node_modules/.staging/xml2js-c5f46ee4
npm verb gentlyRm don't care about contents; nuking /Users/agerson/Desktop/CGPSApp/node_modules/.staging/xml2js-c5f46ee4/node_modules
npm info lifecycle xml2js@0.4.17~preinstall: xml2js@0.4.17
npm verb unbuild node_modules/xml2js
npm info lifecycle xml2js@0.4.17~preuninstall: xml2js@0.4.17
npm info lifecycle xml2js@0.4.17~uninstall: xml2js@0.4.17
npm verb unbuild rmStuff xml2js@0.4.17 from /Users/agerson/Desktop/CGPSApp/node_modules
npm info lifecycle xml2js@0.4.17~postuninstall: xml2js@0.4.17
npm verb gentlyRm don't care about contents; nuking /Users/agerson/Desktop/CGPSApp/node_modules/xml2js
npm info linkStuff xml2js@0.4.17
npm verb linkBins xml2js@0.4.17
npm verb linkMans xml2js@0.4.17
npm info lifecycle xml2js@0.4.17~install: xml2js@0.4.17
npm info lifecycle xml2js@0.4.17~postinstall: xml2js@0.4.17
npm verb unlock done using /Users/agerson/.npm/_locks/staging-3d17163a40924b46.lock for /Users/agerson/Desktop/CGPSApp/node_modules/.staging
npm verb saving [ { name: 'xml2js', spec: '^0.4.17', save: 'dependencies' } ]
CGPSApp@0.0.1 /Users/agerson/Desktop/CGPSApp
├── UNMET PEER DEPENDENCY react-native-vector-icons@4.2.0
└── xml2js@0.4.17 

npm WARN @shoutem/animation@0.8.10 requires a peer of react@^15.0.0 but none was installed.
npm verb 
npm verb If you need help, you may report this error at:
npm verb     <https://github.com/npm/npm/issues>
npm WARN native-base@2.3.0 requires a peer of react-native-vector-icons@~4.1.1 but none was installed.
npm verb 
npm verb If you need help, you may report this error at:
npm verb     <https://github.com/npm/npm/issues>
npm verb exit [ 0, true ]
npm info ok 
Adams-iMac-3:CGPSApp agerson$ 

screenshot 2017-07-27 20 29 14

Leonidas-from-XIV commented 7 years ago

I don't know much about React-Native but it looks like it does not offer a Node.js environment?

agersoncgps commented 7 years ago

Its built entirely on top of Node. What makes you question it?

Leonidas-from-XIV commented 7 years ago

The only non-Node dependencies that we currently have is sax and xmlbuilder (though I plan to reduce that too) so I am surprised it would miss modules which are in the Node Stdlib.

dousaitis commented 7 years ago

I also tried to use the xml2js in a my react-native app and I had similar issues. The solution was to install all required xml2js dependencies in my react-native app.

cd myReactNativeApp
npm install events buffer stream timers --save

Index.js

import React from 'react'
import { View } from 'react-native';
import ExportSvg from './ExportSvg';

const source = `<svg xmlns='http://www.w3.org/2000/svg' width='420' height='420' style='background-color:rgba(240,240,240,1);'>
  <g style='fill:rgba(38,145,217,1); stroke:rgba(38,145,217,1); stroke-width:2.1;'>
    <rect  x='185' y='185' width='50' height='50'/>
    <rect  x='185' y='235' width='50' height='50'/>
    <rect  x='185' y='285' width='50' height='50'/>
    <rect  x='135' y='85' width='50' height='50'/>
    <rect  x='235' y='85' width='50' height='50'/>
    <rect  x='135' y='185' width='50' height='50'/>
    <rect  x='235' y='185' width='50' height='50'/>
    <rect  x='135' y='235' width='50' height='50'/>
    <rect  x='235' y='235' width='50' height='50'/>
    <rect  x='85' y='235' width='50' height='50'/>
    <rect  x='285' y='235' width='50' height='50'/>
    <rect  x='85' y='285' width='50' height='50'/>
    <rect  x='285' y='285' width='50' height='50'/>
  </g>
</svg>`;

export default (props) => (
  <View style={{flex: 1, alignItems: 'center', justifyContent: 'center', backgroundColor: 'powderblue'}} >
    <ExportSvg
      source={source}
    />
  </View>
);

ExportSvg.js

import React from 'react';
import { View, Text } from 'react-native'
import { parseString } from 'xml2js';

class ExportSvg extends React.Component {
  constructor(props) {
    super(props);
    this.state = { svg: <Text>SVG</Text> };
  }

  renderSvg(source){
    parseString(source, (err, result) => {
      if (err) {
        this.setState({ svg: <Text>Error parsing xml.</Text>});
        return;
      }
      this.setState({ svg: <Text>{JSON.stringify(result)}</Text>});
    });
  }

  render(){
    const { source } = this.props;
    return (
      <View>
        {this.state.svg}
        {this.renderSvg(source)}
      </View>
    );
  }
}

export default ExportSvg;
screen shot 2017-07-31 at 01 43 30
elgambet commented 4 years ago

Adding events, stream and timers dependency worked for me in a react-native app.

yarn add events stream timers

or

npm install events stream timers --save

Abhishek12345679 commented 3 years ago

Its built entirely on top of Node. What makes you question it?

It failed because the native React runtime does not include the Node standard library. Read more at https://docs.expo.io/workflow/using-libraries/#using-third-party-libraries

sliwalker commented 2 years ago

I am using xml2js@0.4.11 with react-native-windows@0.67.4 and needed to add these libs manually:

yarn add buffer events stream timers

Added this addtionally: yarn add @types/xml2js -D

juan-ramirez-dev commented 2 months ago

I using react 18.0.0, only in a web project.

If you have a webpack.config.js and in your resolve.alias have a events configuration, delete the line


  resolve: {
    alias: {
      './locale': 'moment/locale',
      events : path.resolve(__dirname, "src/events"), //Delete this line
      hooks : path.resolve(__dirname, "src/hooks"),
    }
  },

And restart your project