babel-plugin-import-graphql icon indicating copy to clipboard operation
babel-plugin-import-graphql copied to clipboard

Import with TypeScript aliases gives error

Open vitalyiegorov opened this issue 5 years ago • 4 comments

Our project uses TS alias imports and we get the following error: import Query from '@shared/file.graphql'; Error: Cannot find module '@shared/file.graphql'

Only relative imports work: import Query from '../file.graphql';

vitalyiegorov avatar Nov 19 '19 12:11 vitalyiegorov

Same here, but with using webpack aliases.

buesing avatar Dec 19 '19 12:12 buesing

Yes: image image

No: image

PS: "gQLDir" is webpack aliases. image

eError: image

LP1994 avatar Jun 12 '20 10:06 LP1994

When using dynamic import, modifying ". Graphql" will trigger recompilation! But static import will not!

SO!!! Recommended: import('gQLDir/GraphQLDemo.graphql'); OR import('../../../graphQL/GraphQLDemo.graphql');

With the dynamic import I mentioned above, there is no need to use script commands to delete the cache.

LP1994 avatar Jun 13 '20 03:06 LP1994

Alias cannot be used with "babel-plugin-import-graphql". But!!! Only "graphql-tag/loader","babel-plugin-import-graphql" are not used, but aliases can be used. { test: /.(graphql|gql)$/i, use: [ { loader: 'graphql-tag/loader', }, ], },

LP1994 avatar Jun 13 '20 23:06 LP1994