nodejs / help

:sparkles: Need help with Node.js? File an Issue here. :rocket:
1.45k stars 278 forks source link

Upgrade form node 16-20 npm run build:dev emmitted issues #4283

Closed Dhiren321 closed 1 month ago

Dhiren321 commented 8 months ago

I have updated the node version form 16 to 20 npm install was successful

however when I run npm run build:dev

I get following output

> npm run build:dev

> webapp@0.1.0 build:dev
> node build.before.js --mode=development && node ./node_modules/webpack/bin/webpack.js --config webpack.config.vendor.js && node ./node_modules/webpack/bin/webpack.js --config webpack.config.js

======= build.before.js mode: DEVELOPMENT =======
=== Webpack vendor compilation mode: development ===
Hash: 8dbd7d3a04e914f1d5ffa3c9bf642b6b24d31673
Version: webpack 4.41.2
Child
    Hash: 8dbd7d3a04e914f1d5ff
    Time: 2795ms
    Built at: 02.11.2023 15.07.50
             Asset      Size  Chunks                   Chunk Names
        vendor.css   170 KiB  vendor  [emitted]        vendor
    vendor.css.map   213 KiB  vendor  [emitted] [dev]  vendor
         vendor.js  6.27 MiB  vendor  [emitted]        vendor
     vendor.js.map  3.51 KiB  vendor  [emitted] [dev]  vendor
    Entrypoint vendor = vendor.css vendor.js vendor.css.map vendor.js.map
    Child mini-css-extract-plugin node_modules/css-loader/dist/cjs.js!ClientApp/styles/loaders/applicationLoader.css:
        Entrypoint mini-css-extract-plugin = *
    Child mini-css-extract-plugin node_modules/css-loader/dist/cjs.js!node_modules/bootstrap/dist/css/bootstrap.min.css:
        Entrypoint mini-css-extract-plugin = *
    Child mini-css-extract-plugin node_modules/css-loader/dist/cjs.js!node_modules/react-toastify/dist/ReactToastify.css:
        Entrypoint mini-css-extract-plugin = *
Child
    Hash: a3c9bf642b6b24d31673
    Time: 3222ms
    Built at: 02.11.2023 15.07.50
        Asset      Size  Chunks             Chunk Names
    vendor.js  7.14 MiB  vendor  [emitted]  vendor
    Entrypoint vendor = vendor.js
=== Webpack compilation mode: development ===
=== Webpack compilation mode: development ===
Starting type checking service...
Using 1 worker with 2048MB memory limit
Starting type checking service...
Using 1 worker with 2048MB memory limit
Hash: 6ec813d0d328817c82d2656f27fb090840e7cde5
Version: webpack 4.41.2
Child
    Hash: 6ec813d0d328817c82d2
    Time: 12755ms
    Built at: 02.11.2023 15.08.05
                                   Asset      Size       Chunks                          Chunk Names
    03c3c9f713c00fb61ad9b9185adcb68f.jpg  73.1 KiB               [emitted]
    06cff386ea64714e395e94ac6fb65bff.jpg  24.3 KiB               [emitted]
    11c6f886583f719a9902d1b7338ee340.png  7.36 KiB               [emitted]
    1465f5afbc86a847d8f0b5d783cffdaa.png  3.64 KiB               [emitted]
    150c1d7e8412e67a27e571efb9febad9.png  4.56 KiB               [emitted]
    2022d8c93a1f9c226868973b30335717.gif   201 KiB               [emitted]
    272aca1a8c1e0782728b312e7361f284.jpg  11.1 KiB               [emitted]
    367af8589c3a68e8ba38d6fd046940ee.jpg    33 KiB               [emitted]
    39ebfdbb73a65ce2a0fef25892ac5056.png  23.2 KiB               [emitted]
    4937fcee2c3699ef0db4a93ff8b80318.png  6.67 KiB               [emitted]
    594e3cb8680f106f17abda44a960cdf3.jpg  62.6 KiB               [emitted]
    6f3aca8694a51bd410527bc80caedbd9.png  8.89 KiB               [emitted]
    7d9507a8413b910cbd5a0fc890dc8805.png  11.2 KiB               [emitted]
    8341b280243ff435423510f6fb0fa730.jpg  78.3 KiB               [emitted]
    a12cef863dbe46394955063bed608521.jpg  73.6 KiB               [emitted]
    b4fc64a6569f2767cff0d4223c11bf53.jpg  72.7 KiB               [emitted]
    e35706f6a8645c467eabdf2adb0420ca.jpg   198 KiB               [emitted]
    ee5ef83c6bd4817d6ad8d5c9fc4a2642.jpg  53.3 KiB               [emitted]
    f7022b9f52a96d91b9bee0804427145c.png  4.85 KiB               [emitted]
    fac56b0360af7ca4763c30690cb7d627.png  2.43 KiB               [emitted]
    fda033d099abeac4dbd636828a9aeaf8.png   1.1 KiB               [emitted]
                          main-client.js  12.8 MiB  main-client  [emitted]        [big]  main-client
                      main-client.js.map  3.54 KiB  main-client  [emitted] [dev]         main-client
    Entrypoint main-client [big] = main-client.js main-client.js.map
Child
    Hash: 656f27fb090840e7cde5
    Time: 11506ms
    Built at: 02.11.2023 15.08.03
                                   Asset      Size       Chunks                    Chunk Names
    03c3c9f713c00fb61ad9b9185adcb68f.jpg  73.1 KiB               [emitted]
    06cff386ea64714e395e94ac6fb65bff.jpg  24.3 KiB               [emitted]
    11c6f886583f719a9902d1b7338ee340.png  7.36 KiB               [emitted]
    1465f5afbc86a847d8f0b5d783cffdaa.png  3.64 KiB               [emitted]
    150c1d7e8412e67a27e571efb9febad9.png  4.56 KiB               [emitted]
    2022d8c93a1f9c226868973b30335717.gif   201 KiB               [emitted]
    272aca1a8c1e0782728b312e7361f284.jpg  11.1 KiB               [emitted]
    367af8589c3a68e8ba38d6fd046940ee.jpg    33 KiB               [emitted]
    39ebfdbb73a65ce2a0fef25892ac5056.png  23.2 KiB               [emitted]
    4937fcee2c3699ef0db4a93ff8b80318.png  6.67 KiB               [emitted]
    594e3cb8680f106f17abda44a960cdf3.jpg  62.6 KiB               [emitted]
    6f3aca8694a51bd410527bc80caedbd9.png  8.89 KiB               [emitted]
    7d9507a8413b910cbd5a0fc890dc8805.png  11.2 KiB               [emitted]
    8341b280243ff435423510f6fb0fa730.jpg  78.3 KiB               [emitted]
    a12cef863dbe46394955063bed608521.jpg  73.6 KiB               [emitted]
    b4fc64a6569f2767cff0d4223c11bf53.jpg  72.7 KiB               [emitted]
    e35706f6a8645c467eabdf2adb0420ca.jpg   198 KiB               [emitted]
    ee5ef83c6bd4817d6ad8d5c9fc4a2642.jpg  53.3 KiB               [emitted]
    f7022b9f52a96d91b9bee0804427145c.png  4.85 KiB               [emitted]
    fac56b0360af7ca4763c30690cb7d627.png  2.43 KiB               [emitted]
    fda033d099abeac4dbd636828a9aeaf8.png   1.1 KiB               [emitted]
                          main-server.js  10.3 MiB  main-server  [emitted]  [big]  main-server
    Entrypoint main-server [big] = main-server.js

after this when I run the code I get the following in console

Failed to load resource: the server responded with a status of 500 () vendor.js:1 

 Failed to load resource: the server responded with a status of 500 ()
main-client.js:1 

Failed to load resource: the server responded with a status of 500 ()
vendor.css:1 

what does [emitted] mean in the npm run build:dev output and how to solve it so my main-client.js, vendor.js and vendor.css loads?

Dhiren321 commented 8 months ago

here is my package.json

{
  "name": "webapp",
  "private": true,
  "version": "0.1.0",
  "devDependencies": {
    "@babel/core": "7.7.2",
    "@hot-loader/react-dom": "16.11.0",
    "@types/history": "4.7.3",
    "@types/react": "16.9.11",
    "@types/react-dom": "16.9.4",
    "@types/react-helmet": "5.0.14",
    "@types/react-redux": "7.1.5",
    "@types/react-router": "5.1.3",
    "@types/react-router-dom": "5.1.2",
    "@types/webpack": "4.41.0",
    "@types/webpack-env": "1.14.1",
    "aspnet-prerendering": "3.0.1",
    "aspnet-webpack-react": "4.0.0",
    "babel-loader": "8.0.6",
    "babel-plugin-import": "^1.13.0",
    "case-sensitive-paths-webpack-plugin": "2.2.0",
    "css-loader": "3.2.0",
    "cssnano": "4.1.10",
    "file-loader": "4.2.0",
    "fork-ts-checker-webpack-plugin": "3.1.0",
    "ignore-loader": "0.1.2",
    "mini-css-extract-plugin": "0.8.0",
    "node-noop": "1.0.0",
    "optimize-css-assets-webpack-plugin": "5.0.3",
    "react-dev-utils": "9.0.1",
    "react-dropzone": "^14.2.2",
    "react-hot-loader": "4.12.18",
    "rimraf": "3.0.0",
    "sass": "^1.64.1",
    "sass-loader": "^10.4.1",
    "style-loader": "1.0.0",
    "terser-webpack-plugin": "1.3.0",
    "ts-loader": "6.2.1",
    "ts-nameof": "4.2.0",
    "ts-nameof-loader": "1.0.2",
    "typescript": "^4.9.5",
    "url-loader": "2.2.0",
    "webpack": "4.41.2",
    "webpack-cli": "3.3.10",
    "webpack-dev-middleware": "3.7.2",
    "webpack-hot-middleware": "2.25.0",
    "webpack-merge": "4.2.2"
  },
  "dependencies": {
    "@babel/polyfill": "7.7.0",
    "@material-ui/core": "^4.11.0",
    "@reduxjs/toolkit": "1.1.0",
    "aspnet-webpack": "3.0.0",
    "aspnet-webpack-react": "4.0.0",
    "awesome-debounce-promise": "2.1.0",
    "axios": "0.21.1",
    "bootstrap": "^4.5.0",
    "chokidar": "^3.5.3",
    "connected-react-router": "6.6.0",
    "core-js": "^3.32.1",
    "custom-event-polyfill": "1.0.7",
    "debug": "^4.3.4",
    "domain-wait": "^1.3.0",
    "event-source-polyfill": "1.0.9",
    "formik": "2.0.4",
    "history": "4.10.1",
    "ini": "^4.1.1",
    "mkdirp": "^3.0.1",
    "nval-tippy": "^1.0.40",
    "query-string": "^5.1.1",
    "react": "16.12.0",
    "react-app-polyfill": "^1.0.6",
    "react-bootstrap": "1.0.0-beta.16",
    "react-dom": "16.12.0",
    "react-helmet": "6.0.0-beta",
    "react-redux": "7.1.3",
    "react-router": "5.1.2",
    "react-router-bootstrap": "0.25.0",
    "react-router-dom": "5.1.2",
    "react-select": "^3.1.0",
    "react-toastify": "5.4.1",
    "redux": "4.0.4",
    "redux-thunk": "2.3.0",
    "uuid": "^9.0.0"
  },
  "browserslist": {
    "production": [
      ">0.2%",
      "not dead",
      "not op_mini all",
      "ie 11"
    ],
    "development": [
      "last 1 chrome version",
      "last 1 firefox version",
      "last 1 safari version",
      "ie 11"
    ]
  },
  "scripts": {
    "build:dev": "node build.before.js --mode=development && node ./node_modules/webpack/bin/webpack.js --config webpack.config.vendor.js && node ./node_modules/webpack/bin/webpack.js --config webpack.config.js",
    "build:prod": "node build.before.js --mode=production && node ./node_modules/webpack/bin/webpack.js --config webpack.config.vendor.js --env.prod=true && node ./node_modules/webpack/bin/webpack.js --config webpack.config.js --env.prod=true"
  }
}

and web.config

const path = require('path');
const webpack = require('webpack');
const merge = require('webpack-merge');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin');
const CaseSensitivePathsPlugin = require('case-sensitive-paths-webpack-plugin');
const WatchMissingNodeModulesPlugin = require('react-dev-utils/WatchMissingNodeModulesPlugin');
const CssNanoPlugin = require("cssnano");
const TerserWebpackPlugin = require("terser-webpack-plugin");
const OptimizeCSSAssetsPlugin = require("optimize-css-assets-webpack-plugin");

module.exports = (env) => {
    const isDevBuild = !(env && env.prod);

    // Configuration in common to both client-side and server-side bundles.
    const sharedConfig = () => {

        var mode = isDevBuild ? "development" : "production";

        console.log('\x1b[36m%s\x1b[0m', "=== Webpack compilation mode: " + mode + " ===");

        var config = {
            mode,
            optimization: {

                moduleIds: 'named',

                minimize: !isDevBuild,
                usedExports: isDevBuild,
                minimizer: !isDevBuild ? [
                    // Production.
                    new TerserWebpackPlugin({
                        terserOptions: {
                            output: {
                                comments: false,
                            },
                        },
                    }),
                    new OptimizeCSSAssetsPlugin({
                        cssProcessor: CssNanoPlugin,
                        cssProcessorPluginOptions: {
                            preset: ["default", { discardComments: { removeAll: true } }]
                        }
                    })
                ] : [
                    //developement
                        new TerserWebpackPlugin({
                            terserOptions: {
                                output: {
                                    comments: false,
                                },
                            },
                        }),
                        new OptimizeCSSAssetsPlugin({
                            cssProcessor: CssNanoPlugin,
                            cssProcessorPluginOptions: {
                                preset: ["default", { discardComments: { removeAll: true } }]
                            }
                        })
                    ]
            },
            stats: { modules: false },
            resolve: {
                extensions: ['.js', '.jsx', '.ts', '.tsx', '.jpg','.ico'],
                alias: {
                    "@Layouts": path.resolve(__dirname, "ClientApp/layouts/"),
                    "@Components": path.resolve(__dirname, "ClientApp/components/"),
                    "@Images": path.resolve(__dirname, "ClientApp/images/"),
                    "@Store": path.resolve(__dirname, "ClientApp/store/"),
                    "@Utils": path.resolve(__dirname, "ClientApp/utils"),
                    "@Styles": path.resolve(__dirname, 'ClientApp/styles/'),
                    "@Pages": path.resolve(__dirname, 'ClientApp/pages/'),
                    "@Services": path.resolve(__dirname, 'ClientApp/services/'),
                    "@Models": path.resolve(__dirname, 'ClientApp/models/'),
                    "@Core": path.resolve(__dirname, 'ClientApp/core/')
                }
            },
            output: {
                filename: '[name].js',
                publicPath: 'dist/', // Webpack dev middleware, if enabled, handles requests for this URL prefix.
            },
            module: {
                rules: [
                    {
                        test: /\.tsx?$/, include: /ClientApp/,
                        use: [
                            {
                                loader: 'babel-loader',
                                options: {
                                    compact: true,
                                    plugins: [
                                    ]
                                },                    
                            },
                            {
                                loader: 'ts-loader',
                                options: {
                                    // Disable type checker - we will use it in fork plugin.
                                    transpileOnly: true
                                }
                            },
                            'ts-nameof-loader'
                        ]
                    },
                    {
                        test: /\.(gif|png|jpe?g|svg)$/i,
                        use: ['file-loader']
                    }
                ]
            },
            plugins: [
                new ForkTsCheckerWebpackPlugin(),
                // Moment.js is an extremely popular library that bundles large locale files
                // by default due to how Webpack interprets its code. This is a practical
                // solution that requires the user to opt into importing specific locales.
                // https://github.com/jmblog/how-to-optimize-momentjs-with-webpack
                // You can remove this if you don't use Moment.js:
                new webpack.IgnorePlugin(/^\.\/locale$/, /moment$/)
            ].concat(isDevBuild ? [
                // Development.

                // Add module names to factory functions so they appear in browser profiler.
                //new webpack.NamedModulesPlugin(),
                // Watcher doesn't work well if you mistype casing in a path so we use
                // a plugin that prints an error when you attempt to do this.
                // See https://github.com/facebookincubator/create-react-app/issues/240
                new CaseSensitivePathsPlugin(),
                // If you require a missing module and then `npm install` it, you still have
                // to restart the development server for Webpack to discover it. This plugin
                // makes the discovery automatic so you don't have to restart.
                // See https://github.com/facebookincubator/create-react-app/issues/186
                new WatchMissingNodeModulesPlugin(path.resolve(__dirname, '..', 'node_modules'))
            ] : [
                // Production.
            ])
        };

        if (isDevBuild) {

            // Change config for development build.

            config = {
                ...config,
                // Turn off performance hints during development because we don't do any
                // splitting or minification in interest of speed. These warnings become
                // cumbersome.
                performance: {
                    hints: false,
                },
                //IE11 isn't a fan of the eval() code that gets inserted by webpack.
                //Using webpackConfig.devtool = 'none' (or one of the alternative values) should fix it
                devtool: 'eval-source-map'
                //devtool: 'none'
            };

            config.resolve.alias = {
                ...config.resolve.alias,
                'react-dom': '@hot-loader/react-dom'
            };
        }

        return config;
    };

    // Configuration for client-side bundle suitable for running in browsers.
    const clientBundleOutputDir = './wwwroot/dist';
    const clientBundleConfig = merge(sharedConfig(), {
        entry: { 'main-client': './ClientApp/boot-client.tsx' },
        module: {
            rules: [
                { test: /\.css$/, use: isDevBuild ? ['style-loader', 'css-loader'] : [MiniCssExtractPlugin.loader, 'css-loader'] },
                { test: /\.(scss|sass)$/, use: isDevBuild ? ['style-loader', 'css-loader', 'sass-loader'] : [MiniCssExtractPlugin.loader, 'css-loader', 'sass-loader'] }
            ]
        },
        output: { path: path.join(__dirname, clientBundleOutputDir) },
        // Some libraries import Node modules but don't use them in the browser.
        // Tell Webpack to provide empty mocks for them so importing them works.
        node: {
            dgram: 'empty',
            fs: 'empty',
            net: 'empty',
            tls: 'empty',
            child_process: 'empty',
        },
        plugins: [
            new webpack.DllReferencePlugin({
                context: __dirname,
                manifest: require('./wwwroot/dist/vendor-manifest.json')
            })
        ].concat(isDevBuild ? [
            // Development.
            new webpack.SourceMapDevToolPlugin({
                filename: '[file].map', // Remove this line if you prefer inline source maps.
                moduleFilenameTemplate: path.relative(clientBundleOutputDir, '[resourcePath]') // Point sourcemap entries to the original file locations on disk
            })
        ] : [
            // Production.
            new MiniCssExtractPlugin({
                filename: "site.css"
            })
        ])
    });

    // Configuration for server-side (prerendering) bundle suitable for running in Node.
    const serverBundleConfig = merge(sharedConfig(), {
        module: {
            rules: [
                { test: /\.(scss|sass)$/, use: "ignore-loader" }
            ]
        },
        resolve: { mainFields: ['main'] },
        entry: { 'main-server': './ClientApp/boot-server.tsx' },
        plugins: [
            new webpack.DllReferencePlugin({
                context: __dirname,
                manifest: require('./ClientApp/dist/vendor-manifest.json'),
                sourceType: 'commonjs2',
                name: './vendor'
            })
        ],
        output: {
            libraryTarget: 'commonjs',
            path: path.join(__dirname, './ClientApp/dist')
        },
        target: 'node'
    });

    return [clientBundleConfig, serverBundleConfig];
};

any changes I need kindly suggest

Dhiren321 commented 8 months ago

any help will be appreciated

github-actions[bot] commented 2 months ago

It seems there has been no activity on this issue for a while, and it is being closed in 30 days. If you believe this issue should remain open, please leave a comment. If you need further assistance or have questions, you can also search for similar issues on Stack Overflow. Make sure to look at the README file for the most updated links.

github-actions[bot] commented 1 month ago

It seems there has been no activity on this issue for a while, and it is being closed. If you believe this issue should remain open, please leave a comment. If you need further assistance or have questions, you can also search for similar issues on Stack Overflow. Make sure to look at the README file for the most updated links.