enderh3art / Ramen-Shop

Jesse's Ramen Shop Portfolio
772 stars 187 forks source link

(npm run dev) issue #12

Open iprathammishra opened 1 year ago

iprathammishra commented 1 year ago

Hi! I am facing these errors while running npm run dev command:

ERROR in ./static/sounds/arcade.mp3 Module build failed (from ./node_modules/file-loader/dist/cjs.js): Error: error:0308010C:digital envelope routines::unsupported at new Hash (node:internal/crypto/hash:71:19) at Object.createHash (node:crypto:133:10) at getHashDigest (D:\Visual Diaries\Cloned\Ramen-Shop\node_modules\file-loader\node_modules\loader-utils\lib\getHashDigest.js:46:34) at D:\Visual Diaries\Cloned\Ramen-Shop\node_modules\file-loader\node_modules\loader-utils\lib\interpolateName.js:113:11 at String.replace () at interpolateName (D:\Visual Diaries\Cloned\Ramen-Shop\node_modules\file-loader\node_modules\loader-utils\lib\interpolateName.js:110:8) at Object.loader (D:\Visual Diaries\Cloned\Ramen-Shop\node_modules\file-loader\dist\index.js:29:48)

ERROR in ./static/sounds/bloop.mp3 {...}

ERROR in ./static/sounds/click.mp3 {...}

ERROR in ./static/sounds/cooking.mp3 {...}

ERROR in ./static/sounds/ding.mp3 {...}

ERROR in ./static/sounds/hologram.mp3 {...}

ERROR in ./static/sounds/whoosh.mp3 {...}

webpack compiled with 7 errors.

RajKandane commented 1 year ago

Step 1: Update Dependencies

  1. Update Dependencies: Make sure all your project dependencies, including file-loader and related modules, are up-to-date. You can use the following commands to update your dependencies:

    npm update

    or

    yarn upgrade
  2. Clear the node_modules Folder: Sometimes, issues like this can be caused by corrupted dependencies. Try deleting the node_modules folder and the package-lock.json or yarn.lock file (depending on your package manager) and then reinstall your dependencies:

    rm -rf node_modules
    rm package-lock.json  # or yarn.lock if using Yarn
    npm install

    or

    rm -rf node_modules
    rm yarn.lock  # or package-lock.json if using npm
    yarn install
  3. Check Node.js Version: Ensure you're using a compatible version of Node.js for your project. Sometimes, using an outdated or incompatible Node.js version can cause issues. Check your Node.js version using:

    node -v

    If needed, consider upgrading Node.js to a more recent LTS version.


  1. Check Webpack Configuration: If you're using Webpack to bundle your project, check your Webpack configuration (usually in webpack.config.js) to make sure that it's correctly set up for handling MP3 files. Ensure that the file-loader configuration is properly set up for MP3 files.


  1. Check MP3 Files: Ensure that the MP3 files themselves are not corrupted or encrypted in a way that's causing issues with the loader. Try opening the MP3 files in a media player to verify their integrity.


  1. Check for Other Security Software: Sometimes, security software or firewalls can interfere with the loading of files. Make sure that there are no security settings or software that could be causing this issue.


  1. Debugging: If none of the above steps resolve the issue, you can try to enable more verbose error messages or debugging information in your build tools. This may provide additional insight into what specifically is causing the error.

After trying these steps, you should be able to identify and resolve the issue with the MP3 file loading in your project. If the problem persists, please provide more information about your project setup and webpack configuration for further assistance.

Step 2: Install the Missing Module

If you still encounter the error after completing Step 1:

  1. Install the Missing Module: Use npm or yarn to install the internal-ip module either globally or locally in your project:

    • To install it globally (not recommended):

      npm install -g internal-ip
    • To install it locally in your project:

      npm install internal-ip --save-dev

      or

      yarn add internal-ip --dev
  2. Check webpack.dev.js: Open your webpack.dev.js file, and ensure that it's not trying to require internal-ip unnecessarily. If it is, you may need to adjust your webpack configuration to remove this dependency or ensure that it's not used inappropriately.

  3. Verify Dependencies: Double-check your project's dependencies to ensure that you have all the required modules and that they are correctly specified in your package.json file.

  4. Run webpack serve again: After installing the missing module, try running npm run dev or yarn dev again to see if the issue is resolved.

Step 3: Address ESM Require Error

If the issue persists and you encounter an ESM require error related to internal-ip:

  1. Open webpack.dev.js: Open the webpack.dev.js file located at C:\Users\rajsk\Downloads\Ramen-Shop-main\bundler\webpack.dev.js.

  2. Change the require Statement: Locate the line where you are requiring internal-ip in your webpack.dev.js file and replace it with an import statement:

    import internalIp from 'internal-ip';

    Ensure that your webpack.dev.js file uses ES module syntax throughout.

  3. Save the File: After making this change, save the webpack.dev.js file.

  4. Run npm run dev Again: Try running npm run dev or yarn dev once more to see if the issue is resolved.

This change should resolve the error related to requiring internal-ip in your webpack configuration. If you encounter any other issues or if your webpack.dev.js file has additional complexities, please provide more details for further assistance.

Step 4: Use the ip Library

  1. First, install the ip library as a development dependency:

    npm install ip --save-dev
  2. Update your webpack.dev.js file to use the ip library:

    const path = require('path');
    const { merge } = require('webpack-merge');
    const commonConfiguration = require('./webpack.common.js');
    const ip = require('ip');
    const portFinderSync = require('portfinder-sync');
    
    const infoColor = (_message) => {
     return `\u001b[1m\u001b[34m${_message}\u001b[39m\u001b[22m`;
    };
    
    module.exports = merge(commonConfiguration, {
     stats: 'errors-warnings',
     mode: 'development',
     devServer: {
       // Change 'host' to '0.0.0.0' to allow access from any IP address
       host: '0.0.0.0',
       port: portFinderSync.getPort(8080),
       open: true,
       https: false,
       allowedHosts: 'all',
       hot: false,
       watchFiles: ['src/**', 'static/**'],
       static: {
         watch: true,
         directory: path.join(__dirname, '../static'),
       },
       client: {
         logging: 'none',
         overlay: true,
         progress: false,
       },
       onAfterSetupMiddleware: function (devServer) {
         const port = devServer.options.port;
         const https = devServer.options.https ? 's' : '';
         const localIp = ip.address(); // Use the 'ip' library here
         const domain1 = `http${https}://${localIp}:${port}`;
         const domain2 = `http${https}://localhost:${port}`;
    
         console.log(`Project running at:\n  - ${infoColor(domain1)}\n  - ${infoColor(domain2)}`);
       },
     },
    });
  3. Save the changes and try running npm run dev again.

This should resolve the compatibility issue and allow you to run your development server without errors related to ERR_REQUIRE_ESM.