ef4 / ember-browserify

ember-cli addon for easily loading CommonJS packages from npm via browserify.
MIT License
172 stars 28 forks source link

Build fails when using ember-cli-ramdisk #16

Open IanVS opened 9 years ago

IanVS commented 9 years ago

I created an issue at ember-cli-ramdisk [https://github.com/ExpressCheckout/ember-cli-ramdisk/issues/8], but thought you might like to know about this as well. When using that addon, I am unable to import modules. For example if I try to import moment from 'npm:moment'; I get the error:

Error: Cannot find module 'moment' from '/mnt/EmberCliRamdisk/borrowers/core_object-input_staging-HpoS1dc8.tmp'
    at /mnt/sdb1/code/websites/borrowers/node_modules/ember-browserify/node_modules/browserify/node_modules/browser-resolve/node_modules/resolve/lib/async.js:50:17
    at process (/mnt/sdb1/code/websites/borrowers/node_modules/ember-browserify/node_modules/browserify/node_modules/browser-resolve/node_modules/resolve/lib/async.js:119:43)
    at /mnt/sdb1/code/websites/borrowers/node_modules/ember-browserify/node_modules/browserify/node_modules/browser-resolve/node_modules/resolve/lib/async.js:128:21
    at load (/mnt/sdb1/code/websites/borrowers/node_modules/ember-browserify/node_modules/browserify/node_modules/browser-resolve/node_modules/resolve/lib/async.js:60:43)
    at /mnt/sdb1/code/websites/borrowers/node_modules/ember-browserify/node_modules/browserify/node_modules/browser-resolve/node_modules/resolve/lib/async.js:66:22
    at /mnt/sdb1/code/websites/borrowers/node_modules/ember-browserify/node_modules/browserify/node_modules/browser-resolve/node_modules/resolve/lib/async.js:21:47
    at Object.oncomplete (fs.js:108:15)

I have no idea what the actual problem is, which is why I brought it up in both repos.

ef4 commented 9 years ago

Browserify is picky about where your tmp folder lives relative to your node_modules folder. If you can mount the actual ramdisk at your-app/tmp instead of just symlinking it, that would probably solve this. Alternatively, you could try symlinking your node_modules folder into the real ramdisk location, so that code being built there can find it via normal node rules.

IanVS commented 9 years ago

@ef4, moving node_modules to /mnt/EmberCliRamdisk//node_modules/ and symlinking back to my project folder seems to be working . . . as long as I don't reboot. :-o

I think I'll just move my Ember project folders to my HDD and avoid the hassle. Thanks for explaining the cause.

stefanpenner commented 9 years ago

@ef4 we have plans to move the tmp folder outside of the project. We will likely need to fixup how ember-browserify works for that. Can we inform browserify of the correct node_modules root/package.json to review?

ef4 commented 9 years ago

As far as I know it's not easy. browserify is trying hard to maintain normal node semantics. node is really picky about only using the node_modules hierarchy.

So I think the right thing to make sure that the project's node_modules is available within the build tree that gets passed to browserify. A symlink should suffice.

stefanpenner commented 9 years ago

@ef4 if symlink works, then fantastic. But does leave our windows friends in a bad spot.

I wonder if we can bend substacks arm

IanVS commented 9 years ago

It worked for me with symlinking node_modules. How would this work for multiple projects if tmp and node_modules both live outside the project folder? I like that ember-cli is self contained as it is now.

stefanpenner commented 9 years ago

node_modules will remain in the project, tmp will not. It is a hazard for editors and other tools watching `tmp/*

stefanpenner commented 8 years ago

@ef4 this will also break with broccoli v1, one thing we could do is make a custom browserify-tmp dir in the project root, thoughts?

stefanpenner commented 8 years ago

This will actually need to be revisited, when broccoli 1.0 happens and tmp moves to system tmp. The solution is to symlink (and junction for our windows friends) in node_modules to the basedir of browserify.