Reputation: 400
I am trying to write a local npm module in ES6, i'm using babel, npm... I have no error when i'm running npm install, but when i'm trying to call the module i have this error :
Cannot find module './lib/daihinmin'
I have tried almost everything in my require :
var daihinmin=require('./lib/daihinmin');
var daihinmin=require('daihinmin');
var daihinmin=require('daihinmin.js');
None of this works and i don't see why :(
This is my module package.json :
{
"name": "daihinmin",
"main": "./lib/daihimin.js",
"scripts": {
"compile": "babel --presets es2015 -d lib/ src/",
"prepublish": "npm run compile"
},
"devDependencies": {
"babel-cli": "^6.5.1",
"babel-preset-es2015": "^6.5.0"
}
}
And this is my app package.json :
{
"name": "MrPresident",
"main": "app.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"dependencies": {
"express": "^4.13.3",
"daihinmin": "./lib/daihinmin"
}
}
screenshot of my application tree
Thanks for your help :-)
Upvotes: 1
Views: 535
Reputation: 400
EDIT
It's fixed thanks to :
Babel 6 changes how it exports default
Just a typo in my export.
export default class Daihimin {
helloWorld() {
console.log("helloWorld");
}
}
Instead of
export default class Daihinmin {
helloWorld() {
console.log("helloWorld");
}
}
Thank you!
But now i've got an other error :
daihinmin.helloWorld is not a function
var daihinmin=require('daihinmin');
daihinmin.helloWorld();
And again i can't understand why :(
Upvotes: 1