Browserify: Bug introduced in 12.0.1 (Breakage with symlink + Babelify)

Created on 17 Mar 2016  ยท  6Comments  ยท  Source: browserify/browserify

Overview

The single line (excluding tests) changed in patch release 12.0.1 causes breakage in applications using symlinks and Babelify.

(I discovered this today, as the latest release of grunt-browserify upgrades Browserify from v11 to v13.)

Specifics

I have a project which uses symlinks in accordance with the Browserify Handbook, arranged as follows:

node_modules/
โ”œโ”€โ”€ ...
โ””โ”€โ”€ appName   -- symlink to 'src/' directory

src/
โ”œโ”€โ”€ ...
โ””โ”€โ”€ main.js

...

.babelrc      -- where Babelify looks for its parameters
...

I then simply execute (the Grunt equivalent of):

browserify src/main.js -o build/app-name.js -s AppName -t babelify

This works perfectly through Browserify 12.0.0, but as of 12.0.1 and beyond, I see the error:

ParseError: 'import' and 'export' may appear only with 'sourceType: module'

This error does not occur (and the build succeeds) if I don't use the symlink in my imports.

As implied above, everything works as it used to if I simply revert the offending line in index.js:
cb(err, res, pkg, file); โ†’ cb(err, res, pkg);

Most helpful comment

After eventually discovering #993, it appears that this may never have been intended to work, in spite of what the documentation suggests. In fact, when someone was kind enough to propose an update to the documentation (substack/browserify-handbook#36, 15 months ago), he was simply ignored.

I have confirmed that adding a src/package.json solves the issue:

{ "browserify": { "transform": ["babelify"] } }

Perhaps not a satisfying solution, but a solution nonetheless.

Really, I'm just in disbelief at the total lack of attention and documentation that this problem has received.

All 6 comments

Is anyone looking into this? Seems like a pretty simple fix for a pretty horrendous bug.

It would be really awesome if we could get this fixed...

Is there an open pull request?

There is not, mainly because I don't fully understand the change that was made. (As best I can tell, the goal of the change was to avoid applying transforms to npm linked packages? But that's obviously illegitimate if it blocks the application of transforms to symlinked source code.)

That said, I would be happy to submit an "accept or counterpropose" PR reverting the line, if that's what it takes to elicit a response from the maintainers. After a month without activity, I'm honestly scared if this is now a moribund repo... ๐Ÿ˜“

After eventually discovering #993, it appears that this may never have been intended to work, in spite of what the documentation suggests. In fact, when someone was kind enough to propose an update to the documentation (substack/browserify-handbook#36, 15 months ago), he was simply ignored.

I have confirmed that adding a src/package.json solves the issue:

{ "browserify": { "transform": ["babelify"] } }

Perhaps not a satisfying solution, but a solution nonetheless.

Really, I'm just in disbelief at the total lack of attention and documentation that this problem has received.

An added note for others who may be plagued with this issue:

It appears that this is one of the many philosophical differences between Browserify and Webpack.
Migration to the latter is trivial (thanks to this how-to page), there's no need to modify the source code or project structure whatsoever, and the resulting behavior is as expected above.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

andrepadez picture andrepadez  ยท  7Comments

3rd-Eden picture 3rd-Eden  ยท  10Comments

ericmorand picture ericmorand  ยท  4Comments

thlorenz picture thlorenz  ยท  5Comments

ericmorand picture ericmorand  ยท  6Comments