I upgraded the node and built the existing file.
But it didn't build, and there was an error.
Error [ERR_REQUIRE_ESM]: Must use import to load ES Module: │ │ ~~/nuxt.config.js │ │ require() of ES modules is not supported. │ │ require() of ~~/nuxt.config.js from │ │ ~~/config.js is an ES │ │ module file as it is a .js file whose nearest parent package.json contains "type": │ │ "module" which defines all .js files in that package scope as ES modules. │ │ Instead rename nuxt.config.js to end in .cjs, change the requiring code to use │ │ import(), or remove "type": "module" from │ │ ~~/package.json.
So I removed 'type: module' in package.json file.
Is it okay to remove it?
A script tag having type="module" attribute specifies that it to be considered as a Javascript module. It may be importing other Javascript module(s) inside it and becomes a "top-level" module for the imported modules.
The main field makes sure that Node users using require will be served the UMD version. The module field is not an official npm feature but a common convention among bundlers to designate how to import an ESM version of our library.
To add dependencies and devDependencies to a package. json file from the command line, you can install them in the root directory of your package using the --save-prod flag for dependencies (the default behavior of npm install ) or the --save-dev flag for devDependencies.
Your package. json holds important information about the project. It contains human-readable metadata about the project (like the project name and description) as well as functional metadata like the package version number and a list of dependencies required by the application.
When you have 'type': 'module'
in the package.json
file, your source code should use import
syntax. When you do not have, you should use require
syntax.
Adding 'type': 'module'
to the package.json
enables ES 6 modules. For more info, see here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With