Roots Discourse

Sage10 - webPackConfig - node_modules

I’ve spent the day converting my Sage 9 theme to Sage 10. The final hurdle is allowing my component js files to import from node modules

my js folder structure:

- scripts
app.js
   --components
   componentFile.js
   --routes
   routeFile.js

In one of my components, I’m trying to import lodash. I’ve tried both
import _ from 'lodash' and const _ = require('lodash')

There are no compile errors but _ is undefined in the browser console.

I’ve messed with several of the laravel mix methods but none seem to resolve my issue.

I was hoping setting a custom webpackConfig would help, it didn’t

.webpackConfig({
  resolve: {
      modules: ['node_modules'],
  },
})

Any assistance would be greatly appreciated!

On a side note, how come js router was removed from Sage 10?

window._ = require('lodash')

Thanks for your reply. I managed to solve my particular issue with lodash by importing the methods separately

import keys from 'lodash/keys'
import isNull from 'lodash/isNull'