require is not defined error with browserify

前端 未结 4 1318
余生分开走
余生分开走 2020-12-02 17:17

I\'m new to browserify and trying to load npm modules in browser but I\'m getting the following error:

Uncaught ReferenceError: require is not defined

4条回答
  •  余生分开走
    2020-12-02 18:00

    Short answer: remove the script.js import

    Longer answer: You are getting the error because the method requireis not defined in the browser. You shouldn't include script.js.

    The idea behind Browserify is that you can split up your sources using CommonJS modules and bundle them into one file to be used in the browser. Browserify will traverse all your sources and will concatenate all required files into the bundle.

提交回复
热议问题