Local node_modules and meteor

Hello,

I’m trying to create a custom node modules, but i have a “SyntaxError: Unexpected reserved word” when i use “import React from ‘react’;” so i’m not sure how to integrate it with meteor :

  • do i need to add babel integration to it in order to use ES6 ? if yes how to add it seemlessly with a meteor project ?
  • more generally how do you integrate custom node_modules with meteor ?
  • how you import/require meteor stuff inside node_modules ? ( i’m not sure if it’s possible :confused: but i prefer to ask ^^)

hope you can help me :slight_smile:

do i need to add babel integration to it in order to use ES6 ? if yes how to add it seemlessly with a meteor project ?

If you’ve added the “ecmascript” package (meteor add ecmascript) it should be able to transpile es2015 (aka es6) to es5 without any more effort.

how you import/require meteor stuff inside node_modules ?

If you mean importing something from node modules: When you import it automatically looks inside ./node_modules if you didn’t give a specific path but just a packge name. So when you do npm install some-package, it gets installed into ./node_modules/some-package/. When you import someVar from 'some-package' it will import the file declared in ./node_modules/some-package/package.json "main" field.

If you mean importing a Meteor API from inside an npm package: I believe you should just be able to import it via `import Meteor from ‘meteor/meteor’ like you normally would

more generally how do you integrate custom node_modules with meteor ?

if you mean that you have an npm package that’s published to npm and you want to install it, you can just install it like any other npm package with npm install your-package-name. Otherwise if you have a package that isn’t published to npm but it’s in a git repo somewhere (like on your github), you can add it to your package.json pointing right to your repo like

"dependencies": {
    "your-package-name": "git+https://github.com/your-username/your-project.git"
}

and then just do npm install, it’ll be installed to ./node_modules/your-package-name/ and you’ll be able to import it like import something from 'your-package-name'

hope that helps :slight_smile:

For local node module development you can make a folder for you package (outside your app project) then

cd /path/to/node-package

npm link

cd /path/to/app

npm link my-package

and add this to your package.json so that it’s registered as a dependency:

"my-package": "file:node_modules\\my-package",

and take a look at this repo for an example node package: https://github.com/benjamn/jsnext-skeleton

then change:

 "dependencies": {
  "babel-runtime": "^5.8.25"
},
"devDependencies": {
  "babel": "^5.8.23",
  "mocha": "^2.3.3"
}

to

"devDependencies": {
  "babel-core": "^6.0.0"
}

Thanks, both of you, for your detailed answers, that clarifies some points in my mind ^^

concerning “how you import/require meteor stuff inside nodemodules ?_”

Sorry, but i think my question where not clear enough : i want to create a node_modules “super-module” and import meteor package like “import { Meteor } from ‘meteor/meteor’;” inside that “super-module”. I’m not sure if it’s possible yet, but as i said, i prefer to ask ^^.

Yeah, I don’t believe that’s possible… you’ll have to rely on globals