1.3.3 imports breaking

import * as Collections from '/lib/collections';

This worked fine in 1.3.2, however since I’ve upgraded to 1.3.3 I get the following error:

Unable to resolve some modules:

  "/Users/josh/Projects/CLIENT/codebase/lib/collections" in /Users/josh/Projects/CLIENT/codebase/client/configs/context.js (web.browser)

Likewise on the server:

Unable to resolve some modules:

  "/Users/josh/Projects/CLIENT/codebase/lib/collections" in /Users/josh/Projects/CLIENT/codebase/server/publications/file_name.js (os.osx.x86_64)

Any ideas?
Thanks!

1 Like

Not sure I can answer your question, but I can shed light on the “./” notation. That is forming a reference relative to the current directory. So, on the client side “./lib/collections” is asking it to look for /Users/josh/Projects/CLIENT/codebase/client/configs/lib/collections.

So is /lib/collections a directory with an “index.js”? If not and it is actually an attempt to reference /lib/collections.js, did you try adding “.js” to the initial example? It seems like I had a problem where I had left some “.js” extensions off and it worked for a while and then stopped. I just added the extensions without thinking about it. I’ve been using the development branches for Meteor 1.4 for a while, so I may have hit the problem you’re encountering when I switched without consciously realizing it.

1 Like

I also faced the same issue. So to fix it I had to go through all the files and change the paths. All the paths relative to the root of the project have to be changed to be relative to the directory where the file is in. So, this : import * as Collections from '/lib/collections'; had to be re-written to this : import * as Collections from '../../lib/collections';

Thanks for the tip @rlivingston Anyway, any idea why it’s happening?

It seems like a bug to me. You should be able to import your file using import * as Collections from '/lib/collections';, but somehow meteor thinks you mean the filesystem root instead of your project root.

FYI, I think this may be a different manifestation of meteor issue #7221. It appears to be a Windows specific problem. I’d bet they are fast at work on 1.3.3.1.

Also, note that absolute paths that relate to the project’s root directory are very definitely supported. I spent some time yesterday looking at the Meteor tool test code and found that the very first test in their modules test package checks whether an absolute path works.

Just updated to 1.3.3.1 and still the problem is there :frowning:

@joshig Did you create an issue in github for this?

Turns out the issue is due to Mantra’s babelrc file, not Meteor itself. Both communities seem to be aware of the issue, so we’ll see what happens.

{
  "presets": ["es2015", "stage-2", "react"],
  "plugins": ["react-require", "babel-root-slash-import"]
}

If you remove the babel-root-slash-import it will work aparently, but other feautres may break, such as testing.

1 Like

Oh… I just updated to the latest version of mantra-core and removed babel-root-slash-import from .babelrc and now it is working!

1 Like

Warning Removing babel-root-slash-import seems to break the tests!

Guys, I just introduce a new version of babel-root-slash-import which works properly inside Meteor.

Here’s a sample app using it: https://github.com/mantrajs/mantra-sample-blog-app

Simply update your babel-root-slash-import to version 1.1.0.

3 Likes

I just updated to the latest version of babel-root-slash-import but still the problem is there :frowning: And also noticed that the tests fail even with that plugin. Looks like the tests can’t find mongo Error: Cannot find module 'meteor/mongo'.

@lcpubs That’s true. We are using pure node based testsing. It can’t understand meteor imports.
In mantra, we write code to avoid Meteor imports. All the meteor imports should go inside the app context file.

Then there won’t be any issues like this.

babel-root-slash-import only does what is says.

Cool! But actually I have used meteor/mongo only inside lib/collections.

Collections are carried using the context in Mantra. So, that won’t be an issue.

Ah thanks… Any idea why the tests are failing and why adding babel-root-slash-import (The latest version) gives an error on missing modules? Those are not meteor imports :slight_smile:

Submit an issue on the GitHub with more info :slight_smile:
If you already did it, link it here.

1 Like

The import issue is fixed :slight_smile: No idea what happened but after updating meteor again, it worked. But the tests still fail regardless of the root slash plugin. The thing is, they work in the sample blog app (With my meteor version). There might be something wrong with my project. But no idea what. Need to find out before opening a ticket! Anyway thanks for the help!