I'm developing a recently-ejected create-react-app
application and need to use an outside module.
I did npm install --save-dev starparam
and am importing the module like this: import starparam from 'starparam';
.
When I run my code in NodeJS with my unit-tests (npm test
) everything works as expected.
But, when I run in the browser (using npm start
) I get syntax errors.
This seems to be because the module I'm using uses ES6 features like arrow functions.
What webpack changes do I need to make so this third-party module is included in the transpile?
I was able to accomplish my goal by:
config/paths.js
to the third-party module folderloaders
array in the module
object in config/webpack.config.dev.js
config/webpack.config.prod.js
--
Adding a new path in config/paths.js
;
starparamSrc: resolveApp('node_modules/starparam'),
Adding a new loader in config/webpack.config.dev.js
:
{
test: /\.(js|jsx)$/,
include: paths.starparamSrc,
loader: 'babel',
query: {
cacheDirectory: true
}
},
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With