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

"Cannot find module ..." Issues after update to 3.2.0? #198

Closed
ptrwllrt opened this issue Jul 3, 2017 · 7 comments · Fixed by #205
Closed

"Cannot find module ..." Issues after update to 3.2.0? #198

ptrwllrt opened this issue Jul 3, 2017 · 7 comments · Fixed by #205

Comments

@ptrwllrt
Copy link

ptrwllrt commented Jul 3, 2017

node v6.10.2
npm 5.0.4

Error: Cannot find module './xregexp' from '/var/www/nodefrontend/current/node_modules/xregexp'
Error: Cannot find module './addons/unicode-properties' from '/var/www/nodefrontend/current/node_modules/xregexp'
Error: Cannot find module './addons/matchrecursive' from '/var/www/nodefrontend/current/node_modules/xregexp'
Error: Cannot find module './addons/build' from '/var/www/nodefrontend/current/node_modules/xregexp'
Error: Cannot find module './addons/unicode-categories' from '/var/www/nodefrontend/current/node_modules/xregexp'
Error: Cannot find module './addons/unicode-scripts' from '/var/www/nodefrontend/current/node_modules/xregexp'
Error: Cannot find module './addons/unicode-base' from '/var/www/nodefrontend/current/node_modules/xregexp'
Error: Cannot find module './addons/unicode-blocks' from '/var/www/nodefrontend/current/node_modules/xregexp'

usage:

import xregexp from 'xregexp';
...
const unicodeWord = xregexp('[\\p{L}\\.\\-\\ ]{1,}');
return unicodeWord.test(str);
...

The installed npm package contains a xregexp-all.js on the root level which is mentioned in the package.json as "main".
However this file tries to require some modules like this:

...
},{}],8:[function(require,module,exports){
var XRegExp = require('./xregexp');

require('./addons/build')(XRegExp);
require('./addons/matchrecursive')(XRegExp);
require('./addons/unicode-base')(XRegExp);
require('./addons/unicode-blocks')(XRegExp);
require('./addons/unicode-categories')(XRegExp);
require('./addons/unicode-properties')(XRegExp);
require('./addons/unicode-scripts')(XRegExp);
...

These requires are broken because the actual files are stored in src/.
So for this particular file the following would be correct.

...
},{}],8:[function(require,module,exports){
var XRegExp = require('./src/xregexp');

require('./src/addons/build')(XRegExp);
require('./src/addons/matchrecursive')(XRegExp);
require('./src/addons/unicode-base')(XRegExp);
require('./src/addons/unicode-blocks')(XRegExp);
require('./src/addons/unicode-categories')(XRegExp);
require('./src/addons/unicode-properties')(XRegExp);
require('./src/addons/unicode-scripts')(XRegExp);
...

Something is fishy here. Did the packaging for the release went wrong? Am I using the module wrong?

@knu
Copy link

knu commented Jul 5, 2017

I'm seeing the same problem. Seems Browserify fails to locate the module "xregexp", and the error message readsError: Cannot find module 'xregexp' from ....

I'm not sure if the current value of main in package.json makes sense at all:

"main": "./lib",

Is ./lib loadable?

@vasyas
Copy link

vasyas commented Jul 10, 2017

The same for React-Native

@epsil
Copy link

epsil commented Aug 5, 2017

It appears that v2.0.0 is the last version that works with Browserify.

epsil added a commit to epsil/spotgen that referenced this issue Aug 5, 2017
@slevithan
Copy link
Owner

slevithan commented Aug 21, 2017

Thank you for reporting. Happy to accept pull requests that address this.

@webmobiles
Copy link

webmobiles commented Oct 20, 2017

the problem is not that the pluggin is not imported?

the right is ?
import addons/unicode/unicode-base ?

@webmobiles
Copy link

not really needed 'import unicode-base' on my react app,
it's working ok, here my code:

import XRegExp from 'xregexp';
export const alpha = (value) => {
  const unicodeWord = XRegExp('^\\p{L}+$');
  return (!unicodeWord.test (value) ? 'validator.alpha' : '');
};

@josephfrazier
Copy link
Collaborator

I was able to reproduce this as follows:

cd $(mktemp -d)
yarn add xregexp browserify
yarn browserify node_modules/xregexp

@knu:

I'm not sure if the current value of main in package.json makes sense at all:

"main": "./lib",

Is ./lib loadable?

Note that in v3.2.0, main points to xregexp-all.js, as indicated by @cainvommars (you can see the file on unpkg). It was changed to ./lib as part of #182. I believe this fixed the issue, as the following currently works on the master branch:

yarn # to build the files in ./lib
yarn browserify .

I'm hoping to release a new version to address this: #205

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

Successfully merging a pull request may close this issue.

7 participants