Reasons for error:
The browser side cannot recognize the require keyword, which is required under node.js environment. It is common to require modules in node_modules folder
Solutions:
Compile the JS file with the tools Browserify or WebPack to make it browser-aware.
// Install Browserify, which I’m using as a global installation
npm install -g browserify
//compile
browserify ./source/module.js -o ./dist/dist.js
You can see the packaged Dist. Js file in the dist directory. The first parameter after
browserify represents the entry of the front-end program to be packaged, -o or > Represents the packaged output file. Browserify automatically completes dependency analysis based on require or Import (ES6, need to install Babel) in the entry file and packages the dependency file into a single file.
The browser side cannot recognize the require keyword, which is required under node.js environment. It is common to require modules in node_modules folder
Solutions:
Compile the JS file with the tools Browserify or WebPack to make it browser-aware.
// Install Browserify, which I’m using as a global installation
npm install -g browserify
//compile
browserify ./source/module.js -o ./dist/dist.js
You can see the packaged Dist. Js file in the dist directory. The first parameter after
browserify represents the entry of the front-end program to be packaged, -o or > Represents the packaged output file. Browserify automatically completes dependency analysis based on require or Import (ES6, need to install Babel) in the entry file and packages the dependency file into a single file.
Read More:
- [How to Fix] NameError: name ‘requests‘ is not defined & NameError: name ‘request‘ is not defined
- An error is reported when passing data pages using Ajax: Vue is not defined
- pyspark : NameError: name ‘spark’ is not defined
- Error reported by gulp: referenceerror: primordials is not defined
- python multiprocessing.pool NameError: name is not defined
- Applet error – referenceerror: regeneratorruntime is not defined
- After node.js is installed, use the instruction node version in vscode to show that it is not an external or internal instruction. The solution is as follows:
- [NLP] NameError in using nltk: name ‘freqdist’ is not defined
- Eslint error handling: ‘QQ’ is not defined
- Error reported using layui $is not defined
- Uncaught ReferenceError: FileAsyncWriter is not defined
- Reference error: ecarts is not defined
- Django project running service reported an error NameError: name ‘OS’ is not defined
- VBA “user defined type not defined” MSXML2.DOMDocument
- Error: ‘default’ is not exported by node_ modules/qs/lib/ index.js
- Vue project, browser error: referenceerror: H is not defined
- Solving the problem of NameError: name ‘reload’ is not defined
- ERROR Invalid options in vue.config.js: “plugins“ is not allowed
- Error in v-on handler: “ReferenceError: XXX is not defined“
- Uniapp ESLint error: ‘uni‘ is not defined no-undef [How to Solve]