Can't import js file

When I try an import a file, my page simply doesn’t render. Here’s the file I’m trying to import:

// vendor/sys.js
export class Sys {
	static func() {
		return 'test';
	}
}

Here’s where I’m trying to import:

// app/routes/txt.js
import Ember from 'ember';

export default Ember.Route.extend({
	model() {
		return 'test';
	}
});

When I add the following line to the router:

import Sys from '../../vendor/sys';

(note: I also tried import {Sys} but neither works)

The page completely stops rendering, but no errors are thrown in console. Am I doing something wrong?

The files within /vendor do not get transpiled. You’ll need to put it in your app folder (anywhere) in order to import. Or, you could use broccoli-babel-transpiler over your vendor tree but that may be a bit more work.

1 Like

Thanks for the suggestion. I moved sys.js to app/system/sys.js and changed the import to import Sys from '../../system/sys'; but unfortunately still no dice.

‘export default class’

export default class Sys {

Still no dice. Happy to provide any more information needed. BTW, should the sys file be .js or .es6? I tried both, neither worked anyway, but I’m wondering if it will matter.

https://github.com/jasonmit/sys-example/commit/ce59198432254e3c105bd5919e3bb759cf9470a1

Thanks, but I’m not looking to actually access any of the data in the sys class and display it on the page. Instead I was going to use it for some path utilities, file reading, etc. What you posted works, but txt.js still does not want to import sys.

I feel like I’m missing something really simple here. This works:

import Ember from 'ember';
import Sys from '../system/sys';

export default Ember.Route.extend({
	model() {
		return Sys.func;
	}
});

Although nothing is displayed in {{model}} the page renders. This makes the entire page not render:

import Ember from 'ember';
import Sys from '../system/sys';

export default Ember.Route.extend({
	model() {
		return Sys.func();
	}
});

It was an example on how you import the module, which was the question.

Push an example to github, and I’ll show you what is wrong. But off the bat, if func isn’t a static/class method then this will likely throw with Sys.func is not a function since you’re not creating an instance of Sys, i.e., new Sys().func()

It is static. Here’s the two files: https://github.com/NomNuggetNom/nomcodes