Requiring 'atom-space-pen-views' give me a `Filter` function


#1

I’m having some issues with atom-build.

When I require atom-space-pen-views to get a hold of the View class alls I get is some function named Filter:

console.log(require('atom-space-pen-views'));

> function Filter(options) {
      if (options == null) {
        options = {};
      }
      this.opts = extend({}, defaults, options);
      this.input = [];
      this.stack = [];
      this.stickyStack = [];
    } 

Might be related to this.

How can I debug this further? in ~/.atom/packages/build/node_modules/atom-space-pen-views/ things look okay (CoffeeScript though). Im not sure where and when it’s compiled to javascript…


#2

This is so weird.

So I have 2 views (save-confirm-view and build-view). They are in separate files. Both do a var View = require('atom-space-pen-views').View.
It appears as this was undefined for the save-confirm-view while it worked in build-view. Really weird.

Both these views are required by my main script build. I changed the order these views are required in, and voilà. It works.

This seems to only affect linux/windows user. My OSX had no issues.

I quickly published a patch (0.22.3) so it works for users, but I’m very eager to hear any theories which might cause this?

EDIT:

I was mistaken. This didn’t solve anything, which leads me to believe there’s a race somewhere.
It seems to me as the require cache is corrupted at some point. When requiring atom-space-pen-views I sometimes get the Filter function described above. I have no idea what that is. But obviously not what I want.


#3

I've managed to reproduce this on OS X by installing your package. I get the same errors. The Filter function is coming from ansi-to-html, but why it's being returned from requiring atom-space-pen-views I have no idea…


#4

Think I’ve figured it out.

atom-space-pen-views is currently version 2.0.0. Your package requires version 2.0.2, which only exists on a non-master branch. When I check out the package and change the dependency to 2.0.0, it works.

I still have no idea why this would cause it to give you ansi-to-html instead, because it is correctly installing version 2.0.2, which should work okay. Something must be pretty messed up with either the module cache or atom-space-pen-views, you should create an issue about this.


#5

I am only able to get this error if I run it as a normal package installation (e.g. it is in ~/.atom/packages/build). If I clone the repo and link it with e.g. apm link, the error doesn’t occur.

Changing to 2.0.0 still gives me the error, but only if it is installed a “normal” package.

You’re absolutely right about the Filter function. Good catch. It only furthers my suspicions that something is bad with require


#6

Posted an issue on atom-space-pen-views: https://github.com/atom/atom-space-pen-views/issues/5

Also, I think the build package differs from most packages as it is written i JavaScript only. Not CoffeeScript.


#7

Ah, very weird. Must be something that apm does when installing packages (I know it puts a lot of extra metadata in the package.json, I think for the module caching)


#8

You’re spot on. It appears as the _atomModuleCache which is set up by apm has an entry which looks like this:

     {
        "name": "atom-space-pen-views",
        "version": "2.0.2",
        "path": "node_modules/ansi-to-html/lib/ansi_to_html.js"
      }

Changing that to

     {
        "name": "atom-space-pen-views",
        "version": "2.0.2",
        "path": "node_modules/atom-space-pen-views/lib/main.js"
      }

and it works.


#9

@kevinsawicki was quick as a bee and resolved this. It was an issue with the module cache in apm and with some precompilation of coffee-script in atom-space-pen-views.

Thanks for the help.


#10

Since this was resolved, I’m going to close the topic in a day if there are no concerns.


#11

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.