Unlike Atmosphere packages, NPM packages don’t export directly into the global context. With ES6 modules, imports are put into private hidden contexts as a security measure, unless attached to the global context.
Try adding the following, which will attach to the global context:
import { _moment } from 'moment';
moment = _moment;
Because console.log(moment) is running from within the secure context. Everything within the file is run securely, but isn’t visible to the browser’s console. Unless it’s attached globally. Then you can inspect the objects from the dev tools.
Note: it’s a common practice to attach things to the global context within the main.js file. You were on the right track there.
You are right. I did not notice first that @grandnewbien checked it in browser console… Btw, so far I imported moment only in those files where it was used, is there any advantage of importing it globally in this way?
This appears to work for moment! Although this was more of a symptom of another npm package I’ve been trying to install.
If an NPM package has dependencies, (specifically, I’m trying to install Techan.js, which uses d3), how would you make sure that these packages are exposed?
Trying
import {_techan} from 'techan';
techan = _techan;
in my /imports/ui/body.js
or even
import {_d3} from 'd3';
d3 = _d3;
import {_techan} from 'techan';
techan = _techan;
actually empties the DOM, letting nothing load, giving an error of: Uncaught TypeError: Cannot read property 'min' of undefined(…)
Which is coming from this line in the packages/modules.js: heikinashi: require('./heikinashi')(indicatorMixin, accessor.ohlc, d3.min, d3.max),
Yet again, I can see that all d3 packages are in the packages.json and node_modules, but trying to import them render the project useless.
Ug. Welcome to import hell. It gets a little wild west from here on out. There’s different standards with dotted notation, slashes, etc. Here are some things you can try:
import { d3, min } from 'd3';
import { min } from 'd3'.min;
import { min } from 'd3.min';
import { min } from 'd3/min';
What you’re trying to do is import a submodule. Or possibly an implied dependency. Something that’s not the default main module. There could be security or implementation considerations preventing you from doing so along the way. So no guarantees.
Oddly enough, someone made an atmosphere package with an outdated d3 and techan.js that does work, (somehow even console.log, without having to do global imports). But it’s so outdated it couldn’t work.
I’ll try digging around to see how dependencies were defined within those projects.
Sucks hitting a snag so hard it could kill using meteor as a platform.
I’ve tried both. I verify that it’s in node_modules, but that min error still shows up. I’ve tried so many variations it’s crazy. I have a feeling techan.js referencing d3 isn’t being permitted, as alluded by @awatson1978