Open xmlking opened 1 year ago
Could you create a reproduction repo? Thanks!
Dockerfile
FROM node:19-alpine as runtime
# install pnpm
RUN corepack enable; corepack prepare pnpm@8.1.0 --activate
WORKDIR /app
# clean install dependencies, no devDependencies, no prepare script
COPY .npmrc package.json pnpm-lock.yaml .meshrc.yml ./
RUN pnpm fetch --prod --unsafe-perm --ignore-scripts --unsafe-perm
RUN pnpm install -r --offline --prod
COPY . .
RUN pnpm build
RUN pnpm prune --prod --no-optional
############################################################
### stage_final
############################################################
FROM gcr.io/distroless/nodejs:18 as final
USER nonroot
ENV NODE_ENV production
WORKDIR /app
ENTRYPOINT ["/nodejs/bin/node"]
COPY --from=runtime --chown=nonroot:nonroot /app/.mesh ./.mesh
COPY --from=runtime --chown=nonroot:nonroot /app/config ./config
COPY --from=runtime --chown=nonroot:nonroot /app/src ./src
COPY --from=runtime --chown=nonroot:nonroot /app/tsconfig.json ./tsconfig.json
COPY --from=runtime --chown=nonroot:nonroot /app/package.json ./package.json
COPY --from=runtime --chown=nonroot:nonroot /app/node_modules ./node_modules
ENV PORT 4000
EXPOSE 4000
CMD ["node_modules/@graphql-mesh/cli/cjs/bin.js", "start"]
tsconfig.json
{
"compilerOptions": {
"outDir": "dist",
"skipLibCheck": true,
"target": "esnext",
"moduleResolution": "node",
"module": "commonjs",
"lib": ["esnext"],
"allowSyntheticDefaultImports": true,
"esModuleInterop": true
},
"include": ["src"],
"exclude": ["node_modules"]
}
Could you create a repo so we can run and reproduce?
@ardatan sorry for the delay. here is the repo to reproduce this issue
To reproduce error, run:
git clone https://github.com/xmlking/graphql-mesh-specific
cd graphql-mesh-specific
pnpm i
pnpm build
pnpm start
Error
💥 🕸️ Mesh Error: Cannot find module './src/middleware/custom-fetch.ts'
Require stack:
- /graphql-mesh-specific/.mesh/index.ts
This should work without error
pnpm dev
I debugged this a bit and the issue is basically here:
which then calls:
A very hacky fix:
const relativeModuleName = cross_helpers_1.path.isAbsolute(moduleName) ? (type === 'fetch' ? `../${name}` : moduleName ) : moduleName;
I don't have time to dedicate to finding all the ways this (or a better fix) could break things (i.e. a proper solution).
For now, I'll likely sed my way out of this but maybe this helps someone more knowleadgeable to fix this quicker.
Btw this doesn't only affect docker environments. This happens calling yarn run mesh build
.
I am using
customFetch
andadditionalEnvelopPlugins
with scripts pointing in mysrc
as shown below. everything works fine locally, but when I am doing docker build, I am getting import path error forcustomFetch
This works in local run i.e,
npm run dev
but when dockerized and run, it is failing with path issues forcustomFetch
Workaround: I have to use this during docker build to make it work. (obviously not going to work for local run)
Note:
additionalEnvelopPlugins
has no issues.I think the root cause is how imports are generated in
.mesh/index.ts