Closed hardfist closed 7 years ago
I think that you are running the init function like require('module-alias')()
that is trying to get the config from package.json
. Have you tried something like this? Does it work for you?
const moduleAlias = require('module-alias')
moduleAlias.addAlias('@client', __dirname + '/src/client')
this following is my init function, and I don't read config from package.json so I think it shouldn't throw an error
const moduleAlias = require('module-alias');
const dev = process.env.NODE_ENV === 'development';
if(dev) {
moduleAlias.addPath(path.resolve(__dirname, '../public/js'));
moduleAlias.addAliases({
img: path.resolve(__dirname, '../public/img'),
scss: path.resolve(__dirname, '../public/scss')
});
} else {
moduleAlias.addPath(path.resolve(__dirname, './public/js'));
moduleAlias.addAliases({
img: path.resolve(__dirname, './public/img'),
scss: path.resolve(__dirname, './public/scss')
});
}
moduleAlias();
Just remove the moduleAlias();
line in the end, it shouldn't be there
thank you,fixed my problem
I prefer to set it all up programmatically and don't have package.json in my project,but it throws an error
I think since set up programatically doesn't depend on package.json it shouldn't throw an error