1

I am trying to add webpack.ProvidePlugin which isn't working on Vue-cli 3. I also tried to set lodash as a global import (so I won't have to import it in each store module).

vue.config

const webpack = require("webpack");

module.exports = {
  configureWebpack: {
    plugins: [new webpack.ProvidePlugin({ _: "lodash" })]
  }
};

build Error:

Module Warning (from ./node_modules/eslint-loader/index.js):
error: '_' is not defined (no-undef) at src/store/modules/templates.js:24:10:
  22 | export default Object.assign({}, base, {
  23 |   namespaced: true,
> 24 |   state: _.cloneDeep(initialState),
     |          ^
  25 |   mutations: {
  26 |     addTemplate(state, template) {
  27 |       if (!template) throw new Error("template is missing");

I built the project after adding the lines to vue.config and they gave me the aforementioned error.

1 Answer 1

1

The issue doesn't seem to be with Vue CLI but with eslint. See this question for a similar issue (just replace d3 with _): Webpack not including ProvidePlugins

In short, adding this to your eslint config (often found in .eslintrc.js) should make it work:

"globals": {
   "_": true
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.