Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

the imports are not properly generated for customFetch which fail running in docker environment #5297

Open
xmlking opened this issue Apr 5, 2023 · 5 comments

Comments

@xmlking
Copy link

xmlking commented Apr 5, 2023

I am using customFetch and additionalEnvelopPlugins with scripts pointing in my src as shown below.
everything works fine locally, but when I am doing docker build, I am getting import path error for customFetch

This works in local run i.e, npm run dev but when dockerized and run, it is failing with path issues for customFetch
image
Workaround: I have to use this during docker build to make it work. (obviously not going to work for local run)
image

Note: additionalEnvelopPlugins has no issues.

I think the root cause is how imports are generated in .mesh/index.ts
image
image

@xmlking xmlking changed the title the imports are not properly generated for customFetch which causing running in docker environment the imports are not properly generated for customFetch which fail running in docker environment Apr 5, 2023
@ardatan
Copy link
Owner

ardatan commented Apr 5, 2023

Could you create a reproduction repo? Thanks!

@xmlking
Copy link
Author

xmlking commented Apr 5, 2023

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"]
}

@ardatan
Copy link
Owner

ardatan commented Apr 5, 2023

Could you create a repo so we can run and reproduce?

@xmlking
Copy link
Author

xmlking commented Apr 5, 2023

@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

@saimon-moore
Copy link

I debugged this a bit and the issue is basically here:

https://github.com/Urigo/graphql-mesh/blob/30ecdbde782acf9b33e35805bc0f7deacbf4b038/packages/config/src/utils.ts#L103

which then calls:

https://github.com/Urigo/graphql-mesh/blob/30ecdbde782acf9b33e35805bc0f7deacbf4b038/packages/config/src/utils.ts#L66

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants