4

In package.json:

...
"browserify": {
  "transform": [
    "coffee-reactify"
  ],
  "extension": [ ".cjsx", ".coffee", ".js", ".json" ],
  "extensions": [ ".cjsx", ".coffee", ".js", ".json" ]
},
...

When using browserify transform option works as expected, however browserify is not seeing extension(s) options - it throws error and I have to pass extension options manually to browserify...


in gulpfile.coffee

b = browserify
  entries: './' # ./ = root = directory where package.json is
  debug: true
b.bundle()
.pipe(source('client.js'))
.pipe(buffer())
.pipe(gulp.dest(distDir))

in package.json

"browser": "src/client/client",
"browserify": {
  "transform": [
    "coffee-reactify"
  ],
  "extension": [
    "cjsx",
    "coffee",
    "js",
    "json"
  ]
},

src/client/client.cjsx

otherModule = require './other-module' # other-module.cjsx
  1. When I remove coffee-reactify from transforms in package.json then browserify throws error Parsing file .../src/client/client.cjsx: Unexpected token (2:16)

  2. When I put back coffee-reactify to transforms in package.json, then browserify successfully parses client.cjsx as long as I wont require any other .cjsx files from inside of client.cjsx. So for the example code of client.cjsx above browserify throws error: Cannot find module './other-module' from '/src/client - browserify still does not recognize extension...

So browserify reads package.json (recognizes package.browserify.transforms and package.browser fields but it does not recognize extensions)

user606521
  • 14,486
  • 30
  • 113
  • 204

2 Answers2

1

We were running into the same problem. We were able to get it working by adding extensions to the browserify gulp function call.

browserify({
  entries: "src/index.coffee",
  extensions: [".cjsx", ".coffee", ".js", ".json" ]
})

We don't have it in the package.json at all, just in the gulp command.

Jim Hall
  • 6,079
  • 2
  • 16
  • 15
0

Try this:

"browserify": {
  "transform": [
    "coffee-reactify"
  ],
  "extension": [ 
    "cjsx", 
    "coffee", 
    "js", 
    "json" 
  ]
},

Remove the . dots. Take a look at this question.

Community
  • 1
  • 1
marcel
  • 2,967
  • 1
  • 16
  • 25
  • how do your `package` scripts look like? – marcel Jun 25 '15 at 13:22
  • hmm. i searched for the "browserify" part in `package.json` but i did not found "extension". Just "transform" and some others.... Can you try to add the extensiond to your gulp task directly? like: `b = browserify entries: './' # ./ = root = directory where package.json is debug: true extension: [...]` – marcel Jun 25 '15 at 15:22
  • Yes I know it works like that - but I want browserify to use my package.json settings. I don't want to put "extensions" both inside package.json (for other users which will require my lib in browserify) and also inside gulpfile.coffee. I am not sure if its intensional behaviour of browserify or a bug. The fact is that browserify reads package.json but "sees" only browser/transform fields and not extension... – user606521 Jun 25 '15 at 15:27
  • 2
    yes, i understand your problem. how i said, i think that there is no way to define `extensions` in `package.json`.At least from what i have found in the internet. – marcel Jun 25 '15 at 15:39