Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Scoped packages cause build to fail since 0.16.2 #131

Closed
vanruesc opened this issue Sep 22, 2015 · 5 comments
Closed

Scoped packages cause build to fail since 0.16.2 #131

vanruesc opened this issue Sep 22, 2015 · 5 comments

Comments

@vanruesc
Copy link
Contributor

I use scoped modules like:

// src/main.js
import Something from "@some/thing";

The external package would be:

// node_modules/@some/thing/package.json
{
  ...
  "jsnext:main": "src/index",
  ...
}

// node_modules/@some/thing/src/index.js
export default {};

This works in 0.16.1, but since version 0.16.2 the bundling fails with this error:

> rollup -f cjs -i src/main.js -o build/main.js

ENOENT, no such file or directory 'F:\Sourcecode\JavaScript\MyProject\node_modules\@some\thing.js'
Error: ENOENT, no such file or directory 'F:\Sourcecode\JavaScript\MyProject\node_modules\@some\thing.js'
    at Error (native)
    at Object.fs.openSync (evalmachine.<anonymous>:500:18)
    at Object.fs.readFileSync (evalmachine.<anonymous>:352:15)
    at Object.readFileSync (F:\Sourcecode\JavaScript\MyProject\node_modules\rollup\node_modules\sander\src\methodMakers\standardMethod.js:47:27)
    at _Bundle.defaultLoader [as load] (F:\Sourcecode\JavaScript\MyProject\node_modules\rollup\dist\rollup.js:3193:22)
    at _Bundle.fetchModule (F:\Sourcecode\JavaScript\MyProject\node_modules\rollup\dist\rollup.js:3290:38)
    at F:\Sourcecode\JavaScript\MyProject\node_modules\rollup\dist\rollup.js:3335:21
    at lib$es6$promise$$internal$$tryCatch (F:\Sourcecode\JavaScript\MyProject\node_modules\rollup\node_modules\sander\node_modules\es6-promise\dist\es6-promise.js:331:16)
    at lib$es6$promise$$internal$$invokeCallback (F:\Sourcecode\JavaScript\MyProject\node_modules\rollup\node_modules\sander\node_modules\es6-promise\dist\es6-promise.js:343:17)
    at F:\Sourcecode\JavaScript\MyProject\node_modules\rollup\node_modules\sander\node_modules\es6-promise\dist\es6-promise.js:891:13

Rollup doesn't include the external module's entry point for some reason. Other external modules with no scope work just fine!

@Rich-Harris
Copy link
Contributor

Ah, whoops! I know why this is – since #126, import mod from 'foo/sub/mod' bypasses jsnext:main and retrieves sub/mod.js from within wherever node_modules/foo is.

Fixing it ought to be straightforward but it's a little tricky to test – could I ask you to try plonking this code inside defaultExternalResolver in F:\Sourcecode\JavaScript\MyProject\node_modules\rollup\dist\rollup.js...

function defaultExternalResolver(id, importer) {
  // for now, only node_modules is supported, and only jsnext:main
  var root = absolutePath.exec(importer)[0];
  var dir = dirname(importer);

  // `foo` should use jsnext:main, but `foo/src/bar` shouldn't
  var parts = id.split(/[\/\\]/);

+  // npm scoped packages – @user/package
+  if (parts[0][0] === '@' && parts[1]) {
+    var user = parts.shift();
+    parts[0] = user + '/' + parts[0];
+  }

  while (dir !== root && dir !== '.') {

...and verifying that it works please?

@vanruesc
Copy link
Contributor Author

Tested it and can confirm that it works. Thanks!

@Rich-Harris
Copy link
Contributor

whoops, closed by mistake!

@Rich-Harris Rich-Harris reopened this Sep 27, 2015
@Rich-Harris
Copy link
Contributor

Finally got round to actually releasing this fix, as 0.17.2

@vanruesc
Copy link
Contributor Author

vanruesc commented Oct 1, 2015

Good things take time :) Keep up the good work!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants