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

Importing a module into a module hanging rollup #52

Closed
petulla opened this issue Jul 22, 2015 · 4 comments
Closed

Importing a module into a module hanging rollup #52

petulla opened this issue Jul 22, 2015 · 4 comments

Comments

@petulla
Copy link

petulla commented Jul 22, 2015

Rich

I must be missing something basic.

I have a module foo.js:

  var isTouch = true;
  function fooTest() {
    return isTouch
   }
  export { fooTest }

In my main.js I import it successfully :
import { fooTest } from "foo";

But if I try to import from within another module, say, foo2.js:

import { fooTest } from "foo";

This hangs rollup. What is the stupid thing I am doing wrong?? I'm following this ES6 syntax.

@petulla petulla changed the title Importing module into module hangs Importing a module into a module hanging rollup Jul 22, 2015
@petulla
Copy link
Author

petulla commented Jul 22, 2015

Needed to use a relative path (even though the module is in the same directory as the other module)

import { fooTest } from "./foo";

@Rich-Harris
Copy link
Contributor

Hmmm... interesting that the MDN page has module names ending with .js - haven't seen that elsewhere. By default, Rollup basically does what node/Browserify does (if it's a relative path, gravy, otherwise use the external module resolution algorithm which defaults to looking for node_modules/foo in parent folders).

I discovered the hard way that you can't take shortcuts here - if you use foo to mean 'resolve foo against the base path' (where 'base path' is either explicit, or the directory containing the entry module, or the directory of the importing module), you end up in hot water because no-one else can then consume your package (because they can't make any guarantees about the base path). Even though that doesn't always apply (e.g. you're building an app, not a library to be consumed by others), this is one of those cases where failing early prevents some truly bewildering problems further down the line.

You can override the resolution logic if necessary:

rollup.rollup({
  resolveId: function ( importee, importer ) {
    // simplified example - assumes no external modules
    if ( importee[0] !== '.' ) {
      return path.resolve( baseDir, importee ) + '.js';
    }
    return path.resolve( path.dirname( importer, importee ) ) + '.js';
  },
  // other options
}).then(...)

@petulla
Copy link
Author

petulla commented Jul 22, 2015

Makes sense. Thanks for articulating the use case logic, Rich.

@Twipped
Copy link

Twipped commented Feb 22, 2021

Leaving this here for anyone else who happens to stumble across this thread while trying to solve the same build hang that I've been chasing.

node-sass has an outstanding bug where if the event loop gets halted before it finishes compiling, the thread deadlocks and the process refuses to obey process.exit(). So if you're using rollup-plugin-postcss with sass, and the build fails because of a missing module, node-sass prevents rollup from exiting.

sass/node-sass#1048

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

No branches or pull requests

3 participants