Encountered an error in Nuxt js with Docker: module not found - Error: Unable to locate module

I have been working on a project in Nuxt.js that was running smoothly on my Windows OS without Docker. However, when I tried to set it up inside Docker and run it, I encountered the following errors:

#9 126.5 ERROR in ./pages/index.vue
#9 126.5 Module not found: Error: Can't resolve './main/index.js?vue&type=script&lang=js&' in '/web/pages'
#9 126.5  @ ./pages/index.vue 2:0-61 3:0-56 3:0-56 10:2-8
...
executor failed running [/bin/sh -c apk update && apk upgrade && apk add git python3 && rm -rf node_modules && rm -rf .nuxt && node -v && npm install && npm audit fix && npm run build]: exit code: 1

For reference, here is the tree view of the pages folder in my project:

https://i.sstatic.net/vPaZp.png

The configuration file for Nuxt looks like this:

const isDev = process.env.NODE_ENV !== 'production'

export default {
    ssr: true,
    ...
}

My package.json file contains the necessary dependencies and scripts for the project.

{
    "name": "we",
    "version": "1.0.0",
    "private": true,
    ...
}

The main source of the errors seems to be within the index.vue file:

<template>
  <div>
    <h2>Hello World></h2>
  </div>
</template>
... // Other code here

Here is how the Dockerfile is set up:

FROM node:12.19.0-alpine3.12

ENV APP_ROOT /web
WORKDIR ${APP_ROOT}
ADD . ${APP_ROOT}

RUN rm -rf node_modules && \
    ...
    npm run build

CMD ["npm", "run", "start"]

Why am I encountering these errors when running the project inside Docker?

Answer №1

It appears that there is an issue with the style-loader library not being recognized when your container is running.

Upon further investigation, I noticed that you neglected to include the && on the line where you are installing it in your dockerfile.

Additionally, while it may depend on your specific requirements, I would recommend listing all dependencies in the package.json for consistency. This means moving both eslint-webpack-plugin and style-loader directly into the json file so that the project consistently runs with these libraries included as well.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Unraveling a SQL query result using JavaScript - the ultimate guide!

After exploring related links and conducting a Google search, I unfortunately haven't come across the exact solution to my issue. Apologies for being new to web development, but here's my question: I am working on an ajax JavaScript function tha ...

Having trouble getting dayjs to work in the browser with Vue.js?

Trying to display date differences in a human-readable format using the guide found here: I'm attempting to incorporate DayJS as a component in my VueJS application like this: <script src="{{ asset('/vendor/vuejs/vue.js') }}" t ...

Utilizing Java Nashorn with WebEngine events

I'm having trouble processing events from a webEngine in Nashorn. Despite setting up the code to handle the "load" event, nothing is being printed or indicating that any events are triggering from the webEngine. #!/usr/bin/jjs -fx engine = (v=new(s=j ...

"JavaScript that doesn't rely on a specific browser

Why does this code behave differently across browsers? What modifications are needed to ensure consistent behavior in all of them? In Firefox, it functions correctly, using the URL /some/path/?searchedText=sometext. However, in IE, nothing happens when cli ...

Question about Vue: How can components be rendered dynamically?

Being new to vue and programming in general, I am hoping someone can guide me on how to approach this particular issue. Let's say I have a total of 10 components, each containing a sub-component called (ABC). Within (ABC), there is another component ...

Using ReactJS to trigger a timer function on a button click

Kindly Note: This is a unique query and not related to ReactJS - Need to click twice to set State and run function. The suggested solution there does not resolve my issue. This represents my original state: constructor(props) { super(props) this. ...

Is there a way to modify the fundamental characteristics of a Geometry within Three.js? Such as adjusting the radius, number of vertices, and other parameters?

My task involves creating a tetrahedron with a radius of 3 // create a tetrahedron var tetGeometry = new THREE.TetrahedronGeometry(3); var tetMaterial = new THREE.MeshLambertMaterial( {color: 0x20f020, transparent:true, opacity:0.6}); ...

Exiting or returning from a $scope function in AngularJS: a guide

There are times when I need to exit from my $scope function based on a certain condition. I have attempted to achieve this using the return statement. However, my efforts have been in vain as it only exits from the current loop and not from the main scop ...

What are the best practices for running node in VSCode?

$ node test.js internal/modules/cjs/loader.js:883 throw err; ^ I have exhausted all possible solutions, including checking the PATH route for Node.js, restarting, and using different files. Despite the fact that I am able to retrieve the version when ...

How can I activate the copy function in jQuery?

I'm trying to figure out how to initiate a copy event using JavaScript or jQuery. I need to be able to simulate the copy event by clicking on a button, but I haven't been able to find a solution yet. I want to avoid using ZeroClipboard or any oth ...

What is the best way to pass the setState value to the useEffect hook?

After watching a Youtube video, I took on the challenge of creating my own recipe app using React.js as a beginner. I have been troubleshooting for the past 2 days and seem to have hit a roadblock. The issue lies in passing the value of my state to the use ...

The function yields a resolved promise rather than returning data

I'm trying to use this function: const fetchAndMapData = (): Promise<Data> => { const data = fetch('https://jsonplaceholder.typicode.com/posts') .then((response) => response.json()) .then((items) => items.map((item: ...

How to compare two enums in TypeScript using their string values?

I am working with 2 enums: enum Insurer { PREMERA = 'premera_blue_cross', UHC = 'united_health_care' } enum ProductSource { PremeraBlueCross = 'premera_blue_cross', UnitedHealthCare = 'united_health_care' } ...

Angular 9 date input and selection

I am currently troubleshooting why the attribute value on an input type date is not working with Angular 9. <input type="date" [max]="dateConfig.max" [min]="dateConfig.min" name="date" [value]="dateConfig.val ...

How can I alter the center point of an Object3D in Three.js?

I have a scenario where I am adding meshes dynamically to an Object3D. I'm curious if there is a way to obtain the center of the object so that I can apply rotations and translations evenly across the entire mesh, rather than having them centered on o ...

sending the properties from the menu component to the dish details

Having trouble with a react.js app I'm working on that involves rendering dish cards. The dish object is always null when passed as props from MenuComponent to DishDetail, resulting in nothing being displayed on the screen. Can someone please assist m ...

Identifying iOS versions below 5 using JavaScript

There is an issue with the "fix" for position:fixed in older versions of iOS. However, when iOS5 or higher is installed, this fix actually disrupts the page. I am aware of how to identify iOS 5 using this code: navigator.userAgent.match(/OS 5_\d like ...

Tips on creating vertical stacked content utilizing CSS

Has anyone come across this game before? https://i.sstatic.net/hFX9o.png I am trying to stack each card in a column, here is my fiddle jsfiddle. In my scenario, I have cards wrapped in div elements with a maximum height. If a card exceeds this height, i ...

Having trouble getting Vue UI to install correctly on my new project using Laravel Framework version 8.83.7

I am having trouble installing Vue in my Laravel project. Here are the steps I follow: Run composer require laravel/ui Install Vue using: php artisan ui vue Install Vue with authentication using: php artisan ui vue --auth Then run: npm install ...

Webpack will only load images that are referenced within CSS files, and it will not load images that are referenced within

Within my dist folder, you will find index.html, contact.html, index.js, contact.js, and two images referenced by my css as background images. For example: background-image: url("../images/prairie.jpg"); These are the only items in my dist folder. Any o ...