Not able to use node.js with JavaScript

I am running node.js by importing a js file. But giving below error.

cssValidator.js

import coreStyle from "../../ios/style";

    Here is the code,

    cssValidator.js
    import coreStyle from "../../ios/style";
    const cssValidator = () =\> {
         // Code goes here
    }
    export default cssValidator;

Run npx webpack and create a bundle file

main.js

    `const cssValidator = require('./dist/bundle');
    console.log(cssValidator);
    /\* I am creating a bundle file by using Webpack and Bable \`*/

then running
node main.js

I tried adding “type”: “module” in package.json. Then got the below error.
ReferenceError: require is not defined in ES module scope, you can use import instead
This file is being treated as an ES module because it has a ‘.js’ file extension and ‘./package.json’ contains “type”: “module”. To treat it as a CommonJS script, rename it to use the ‘.cjs’ file extension.

I am expecting to get the data from cssValidator.js and use the code inside main.js to print the computed code

Read more here: Source link