简体   繁体   English

npm run build 返回模块未找到:错误:无法在我的 NuxtJS 应用程序中的 docker 容器中解析

[英]npm run build returns Module not found: Error: Can't resolve in my docker container in my NuxtJS app

I've been on this issue for hours now.我已经在这个问题上讨论了几个小时了。 I kept receiving the error below when I run npm run build当我运行npm run build时,我一直收到以下错误

ERROR in ./store/chatroom.js
Module not found: Error: Can't resolve '@/services/ChatRoomService.js' in '/usr/src/app/store'
 @ ./store/chatroom.js 1:0-60 9:11-26
 @ ./.nuxt/store.js
 @ ./.nuxt/index.js
 @ ./.nuxt/client.js
 @ multi ./.nuxt/client.js

What's weird is, it is working perfectly on my local alone.奇怪的是,它单独在我的本地运行得很好。 The error aboves occur in my docker build and when I run my container with my codebase in it.. However, it is that weirder when I run my container with bind mount on my local and try npm run build it is working properly..上面的错误发生在我的docker build ,当我在其中运行我的代码库的容器时..但是,当我在本地运行带有绑定安装的容器并尝试npm run build它工作正常时,情况就更奇怪了..

At first I thought that maybe some files from my local are missing but I tried copying every file in my local to my container via docker cp .起初我以为我本地的一些文件可能丢失了,但我尝试通过docker cp .本地中的每个文件复制到我的容器中docker cp . but it still does not work..但它仍然不起作用..

Dockerfile文件

FROM node:8.12.0

WORKDIR /usr/src/app
EXPOSE 3000

COPY package.json package.json
RUN npm install

# To include everything
COPY . .

RUN npm run build

ENTRYPOINT ["/usr/src/app/entrypoint.sh"]

chatroom.js聊天室.js

import ChatRoomService from "@/services/ChatRoomService.js";
export const state = () => ({});
export const mutations = {};
export const actions = {
  getText({ commit }, data) {
    return ChatRoomService.queryText(data).then(response => {
      if (response.code === 1) {
        commit("bbs/SET_TOP_ARR", JSON.parse(response.data.content), {
          root: true
        });
      }
    });
  }
};

chatRoomService.js聊天室服务.js

import { mainApiClient, requestSetup } from "@/assets/js/axios.js";

const apiModule = "chatroom";

const resources = {
  chatroomGetChatRoomText: "text/queryText"
};

export default {
  queryText(body) {
    const resource = resources.chatroomGetChatRoomText;
    const [api, req] = requestSetup(resource, body, apiModule);
    return mainApiClient.post(api, req);
  }
};

UPDATE更新

I have solved it.我已经解决了。 It was how I imported.我就是这样导入的。 I imported chatRoomService.js where it should have been ChatRoomService.js .我在应该是ChatRoomService.js地方导入了chatRoomService.js It works just fine in my local because it is Mac but when I put it in a node linux server inside container it is more sensitive它在我的本地工作得很好,因为它是 Mac,但是当我将它放在容器内的节点 linux 服务器中时,它更敏感

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 将 NextJS 项目部署到我自己的服务器(npm run build triggers module not found 错误) - Deploying NextJS project to my own server (npm run build triggers module not found error) 我的应用找不到从 NPM 注册表下载的 TypeScript package(找不到模块) - My app can't find my TypeScript package downloaded from the NPM registry (module not found) 在我的 NodeJS docker 容器中找不到 npm 命令 - The npm command is not found in my NodeJS docker container 运行 npm run build 抛出错误:无法解析“Vue” - running npm run build throws Error: Can't resolve 'Vue' Angular 构建 - 找不到模块:错误:无法解析“控制台” - Angular build - Module not found: Error: Can't resolve 'console' 找不到模块:无法解析“/home/n/MyWork/my-app/src”中的“./clock” - Module not found: Can't resolve './clock' in '/home/n/MyWork/my-app/src' 为什么在我的 Docker 容器中找不到 yarn.lock? - Why can't yarn.lock found in my Docker container? npm - 如果使用 docker 运行,则找不到模块 - npm - module not found if run with docker 为什么我不能修改module.exports? 为什么我的浏览器在 `npm run build` 没有问题后会抱怨? - Why can't I modify module.exports? Why does my browser complain after no problems from `npm run build`? 如何在 Docker 容器中运行我的 React 应用程序 - How to run my react app in Docker container
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM