[英]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.