nolanlawson / rollupify

Browserify transform to apply Rollup (UNMAINTAINED)
Apache License 2.0
386 stars 16 forks source link

require('./...') does not works as expected. #24

Closed drpicox closed 6 years ago

drpicox commented 8 years ago

Rollupify does not works exactly as one expect that it should do.

rollupify only works on ES6/ES2015 modules. Any require() statements will be left untouched, and passed on to Browserify like normal.

But it happens that because it concatenates all files into the current one, when browserify process requires it looses the path.

For example:

// index.js
import { Bob } from './people/bob.js';
Bob.wave();
// ./people/bob.js
let text = require('./text.json');
export class Bob {
    wave() { console.log(text.hello); }
}

Does not work:

Error: Cannot find module './text.json' from '/Users/.../rollupify-poc'

but with this change, it works:

// ./people/bob.js
let text = require('./people/text.json');
export class Bob {
    wave() { console.log(text.hello); }
}

Which is not the expected, neither the convenient.

nolanlawson commented 8 years ago

Thanks for reporting! Related: https://github.com/substack/node-browserify/issues/1379#issuecomment-245024872

fjeldsoe commented 7 years ago

Hi.

When using rollupify in my task runner, it seems like importing from node_modules doesn't work. It just looks in the project root. I don't know if it is related to this issue, but it seems close.

I have:

import {Module} from 'whatever_module';

in one of my .js files, and get the followig error when using the rollupify transform plugin:

[Error: Could not load whatever_module (imported by D:\Projects\root\scripts\component.js): ENOENT: no such file or directory, open 'D:\Projects\root\whatever_module' while parsing file: D:\Projects\root\scripts\main.js]

Am I doing something obvious wrong, or could it be related to this issue? If I remove rollupify, everything works fine.

drpicox commented 7 years ago

I think that it is not related.

By default rollup does not follow node/browserify conventions. You have to use a rollup plugin like:

fjeldsoe commented 7 years ago

@drpicox thanks, that fixed it :)