lock icon indicating copy to clipboard operation
lock copied to clipboard

Unable to build with browserify (nodejs 4.1, npm@3)

Open adrianhall opened this issue 11 years ago • 18 comments

Utilizing gulp + browserify, I get an error when building my app that includes auth0-lock

nodejs 4.1.1, npm 3.3.3, browserify 11.2.0, babelify 6.3.0, auth0-lock 7.9.5, brfs 1.4.1, ejsify 1.0.0, packageify 0.2.2

Build process is in gulp:

function () {
    var b = browserify({
        entries: config.src.jsBundle,
        extensions: ['.js', '.jsx'],
        transform: [ babelify.configure(config.options.babel) ],
        debug: true
    });

    return b.bundle()
        .pipe(source('bundle.js'))
        .pipe(buffer())
        .pipe(sourcemaps.init({ loadMaps: true }))
        //.pipe(uglify(config.options.uglify))
        //.on('error', gutil.log)
        .pipe(sourcemaps.write('.'))
        .pipe(gulp.dest(config.dest.path));
}

The code compiles cleanly when I don't require('auth0-lock');. As soon as I include auth0-lock, I get a compile error:

events.js:141
      throw er; // Unhandled 'error' event
      ^

SyntaxError: Unexpected token (1:0) while parsing file: C:\Users\ADRIANHA\Documents\GitHub\adrianhall\GrumpyWizards\grumpy-wizards\src\Website\node_modules\auth0-lock\lib\html\main.ejs
    at Parser.pp.raise (C:\Users\ADRIANHA\Documents\GitHub\adrianhall\GrumpyWizards\grumpy-wizards\src\Website\node_modules\acorn\dist\acorn.js:1745:13)
    at Parser.pp.unexpected (C:\Users\ADRIANHA\Documents\GitHub\adrianhall\GrumpyWizards\grumpy-wizards\src\Website\node_modules\acorn\dist\acorn.js:2264:8)
    at Parser.pp.parseExprAtom (C:\Users\ADRIANHA\Documents\GitHub\adrianhall\GrumpyWizards\grumpy-wizards\src\Website\node_modules\acorn\dist\acorn.js:1141:12)
    at Parser.pp.parseExprSubscripts (C:\Users\ADRIANHA\Documents\GitHub\adrianhall\GrumpyWizards\grumpy-wizards\src\Website\node_modules\acorn\dist\acorn.js:1023:19)
    at Parser.pp.parseMaybeUnary (C:\Users\ADRIANHA\Documents\GitHub\adrianhall\GrumpyWizards\grumpy-wizards\src\Website\node_modules\acorn\dist\acorn.js:1004:19)
    at Parser.pp.parseExprOps (C:\Users\ADRIANHA\Documents\GitHub\adrianhall\GrumpyWizards\grumpy-wizards\src\Website\node_modules\acorn\dist\acorn.js:948:19)
    at Parser.pp.parseMaybeConditional (C:\Users\ADRIANHA\Documents\GitHub\adrianhall\GrumpyWizards\grumpy-wizards\src\Website\node_modules\acorn\dist\acorn.js:930:19)
    at Parser.pp.parseMaybeAssign (C:\Users\ADRIANHA\Documents\GitHub\adrianhall\GrumpyWizards\grumpy-wizards\src\Website\node_modules\acorn\dist\acorn.js:908:19)
    at Parser.pp.parseExpression (C:\Users\ADRIANHA\Documents\GitHub\adrianhall\GrumpyWizards\grumpy-wizards\src\Website\node_modules\acorn\dist\acorn.js:882:19)
    at Parser.pp.parseStatement (C:\Users\ADRIANHA\Documents\GitHub\adrianhall\GrumpyWizards\grumpy-wizards\src\Website\node_modules\acorn\dist\acorn.js:2461:23)

This is the same compile process that I used with NodeJS 0.12.2 and npm@2 (I just upgraded the node/npm version in the interim). The old compile process (with nodejs-0.12.2 and npm@2) worked fine.

adrianhall avatar Sep 29 '15 21:09 adrianhall

I have narrowed this down to an issue with npm@3 (explicitly 3.3.3 on my system). After getting this error, I do the following:

npm install npm@2
rimraf node_modules
npm install

Then I rebuild the application. It rebuilds without the error and works fine.

adrianhall avatar Oct 02 '15 03:10 adrianhall

I'm seeing a similar issue with grunt + browserify, it's not working on node v5.0.0 & npm v3.3.6. Downgrading to node v4.2.2 & npm v2.14.7 fixes it.

mablack avatar Nov 18 '15 04:11 mablack

@mablack It was the same to me. I guess there's a issue about the way npm3 stores modules in node_modules folder and browserify. http://www.infoq.com/news/2015/06/npm. "Dependencies will now be installed maximally flat. Insofar as is possible, all of your dependencies, and their dependencies, and THEIR dependencies will be installed in your project's node_modules folder with no nesting. You'll only see modules nested underneath one another when two (or more) modules have conflicting dependencies."

osmanpontes avatar Nov 18 '15 13:11 osmanpontes

I have the same issue using Grunt + Browserify, this is how I'm bundling:


function bundle(b, stream) {
  if (!stream) { stream = fs.createOutputStream(appBundle); }
  b
    .transform(babelify, { presets: ['es2015'] })
    .transform(ejsify)
    .transform(brfs)
    .transform(packageify)
    .transform(envify(config.variables[process.env.NODE_ENV || 'DEVELOPMENT']))
    .transform({ global: true, sourcemap: false }, 'uglifyify')
    .bundle()
    .pipe(stream, 'utf8');
}

I'm using node 5.4.0 and npm 3.3.12.

It appears to be failing in the bundle() step.

rhinoceraptor avatar Jan 11 '16 14:01 rhinoceraptor

I have similar issue with my build task using gulp + browserify. npm -version 3.3.12

events.js:141 throw er; // Unhandled 'error' event

SyntaxError: Unexpected token (1:0) while parsing file: <repo_path>/node_modules/auth0-lock/lib/html/main.ejs at Parser.pp.raise (<repo_path>/node_modules/acorn/dist/acorn.js:1745:13)

azazi-sa avatar Jan 18 '16 10:01 azazi-sa

I had the same issue today:

SyntaxError: Unexpected token (1:0) while parsing file: /node_modules/auth0-lock/lib/html/main.ejs
at Parser.pp.raise (/node_modules/acorn/dist/acorn.js:1745:13)

it works when installing the dependencies with npm@2

jfromaniello avatar Jan 18 '16 12:01 jfromaniello

I have same issue. Is there a fix for this? I am unable to downgrade to npm2

anthonyettinger avatar Jan 18 '16 21:01 anthonyettinger

Having the same issue and it's blocking our ability to upgrade to npm@3 for other issues.

sethsamuel avatar Jan 18 '16 22:01 sethsamuel

After doing some digging, it looks like this is a result of https://github.com/substack/node-browserify/issues/1409 which will hopefully be fixed by https://github.com/npm/npm/pull/10185

sethsamuel avatar Jan 19 '16 16:01 sethsamuel

If that's the case, would it be possible to replace the browserify config in Auth0's package.json with an NPM run script that uses CLI browserify?

rhinoceraptor avatar Jan 19 '16 16:01 rhinoceraptor

@sethsamuel thanks for finding the root cause for this.

We are configuring transforms in package.json so browserify can automatically apply them only the auth0-lock module.

"browserify": {
  "transform": ["ejsify", "brfs", "packageify"]
}

However, when installing the package with npm 3, the transforms are sorted alphabetically:

"browserify": {
  "transform": ["brfs", "ejsify", "packageify"]
}

Which is a problem because transforms are applied in the order they appear. brfs is applied before ejsify and this causes the following error:

Error: Line 1: Unexpected token < (/private/tmp/test/node_modules/auth0-lock/lib/html/main.ejs) while parsing file: /private/tmp/test/node_modules/auth0-lock/lib/html/main.ejs

We hope this will be fixed on npm, otherwise we'll have to come up with a workaround.

@rhinoceraptor the same result is obtained when running browserify from the command line. Removing the transforms from package.json will fix the issue, but at the price of manually applying transforms to the module.

gnandretta avatar Jan 20 '16 15:01 gnandretta

There is a pending fix for NPM: https://github.com/npm/npm/pull/10185

anthonyettinger avatar Jan 20 '16 20:01 anthonyettinger

This looks to be fixed with [email protected].

sethsamuel avatar Jan 29 '16 16:01 sethsamuel

:boom:

cristiandouce avatar Jan 29 '16 17:01 cristiandouce

Unfortunately I'm still encountering this issue with [email protected] and [email protected], even after reinstalling all my node_modules. Has anyone else had success with this with the newest NPM?

ghost avatar Feb 03 '16 02:02 ghost

It worked for me on [email protected] and node 5.5.0.

rhinoceraptor avatar Feb 03 '16 02:02 rhinoceraptor

Interesting. OK, I was able to get it to work after installing a fresh node and npm, and reinstalling all my node_modules again.

ghost avatar Feb 03 '16 02:02 ghost

Working now with

 { 
'auth0-lock': '10.2.1',
  npm: '3.10.3',
  ares: '1.10.1-DEV',
  http_parser: '2.7.0',
  icu: '57.1',
  modules: '48',
  node: '6.5.0',
  openssl: '1.0.2h',
  uv: '1.9.1',
  v8: '5.1.281.81',
  zlib: '1.2.8' 
}

Please open a new issue if issue persists.

hzalaz avatar Aug 31 '16 20:08 hzalaz