Import from node_modules not recognized in es6 modules in browser

前端 未结 3 1267
野性不改
野性不改 2020-12-16 20:13

I\'m trying to use lodash in my web application. I have installed lodash using npm in my local project.

I plan on using the ES6 modules in my code.

Here is

相关标签:
3条回答
  • 2020-12-16 20:16

    Try module lodash-es

    import each from '../node_modules/lodash-es/each.js'
    
    0 讨论(0)
  • 2020-12-16 20:20

    If you don't wish to use any bundling tools, you will need to provide a path to the lodash folder within node_modules, relative to the JavaScript file that you have the import statement in.

    If you do not wish to use a bundler, it would also be worthwhile importing from the specific file, the function you need. For example:

    import _each from '../node_modules/lodash/each'
    
    0 讨论(0)
  • 2020-12-16 20:30

    Eventually you can't use JS modules on browser like that. These modules are for webpack or other bundler.

    0 讨论(0)
提交回复
热议问题