Comments (9)
I would suspect that the babel plugin is not doing its work, possibly the artifact dir doesnβt match during webpack resolving π€
Can you see if things work correct without using the artifactDirectory
option?
from relay-compiler-language-typescript.
Just to be sure, did this work with Relay 1.5 without the language plugin support?
from relay-compiler-language-typescript.
Oh wait, I remember now having dealt with something similar in the past. Assuming you did not previously have this setup working without language plugin support, I think the issue is that tsc
is transpiling the code to something like graphql_package.graphql(...)
rather than just graphql(...)
. See the example app for working configuration: https://github.com/relay-tools/relay-compiler-language-typescript/blob/master/example/tsconfig.json
from relay-compiler-language-typescript.
Thanks for the ideas. Losing the artifactDirectory
parameter does not change the outcome and before the upgrade to the language plugin I was using this fork with a custom transformer
"@secoya/relay-compiler": "^1.1.0-secoya",
"@secoya/relay-compiler-typescript": "^1.0.0",
I cross-checked the tsconfig from the example app and this is the example app version with some modifications that produces the same error for me:
{
"compilerOptions": {
"target": "es2015",
"module": "commonjs",
"lib": ["dom", "es2015"],
"sourceMap": true,
"jsx": "react",
"esModuleInterop": true,
"outDir": "dist",
"allowSyntheticDefaultImports": true
},
"types": [
"webpack-env",
"node"
],
"strict": true,
"include": [
"src/**/*"
],
"exclude": [
"node_modules"
],
"files": [
"typings/Core.d.ts"
]
}
However, I was using commonjs
here as module
, otherwise my imports/exports don't seem to work:
$ ./node_modules/.bin/webpack-dev-server
/var/www/dev/admin-frontend/webpack.config.ts:1
(function (exports, require, module, __filename, __dirname) { import * as webpack from 'webpack';
^^^^^^
SyntaxError: Unexpected token import
And indeed, when I look at the unsourcemapped code in my browser, I see:
exports.CaseListTableContainer = react_relay_1.createFragmentContainer(CaseListTable, react_relay_1.graphql `
/.../
`);
Could module
be the determining factor here? Any idea why import/export does not work properly with "module": "es2015"
here?
Thanks a lot!
from relay-compiler-language-typescript.
Yeah the TS module config needs to be set to es2015
for the code to be transpired in a way that the babel plugin will be able to pick it up, as you have found in your above examples.
As for the import
issue, it looks like you may not be using a transform such as babel-plugin-transform-es2015-modules-commonjs
which should be transforming those to commonjs require statements.
PS: @kastermester has started on a tsc plugin as an alternative to the babel plugin, but it has not been finished/released yet afaik.
from relay-compiler-language-typescript.
I have some upcoming plans at work to test out the plugin. You can find it in the PR (#21). It is correct that no test release has been made yet (perhaps that would be a fine move to make though).
I think the help @alloy provided should get you going using the babel plugin however.
from relay-compiler-language-typescript.
I added some documentation about this to the README bdbc0e2, let me know if you have any further thoughts/questions on this topic.
from relay-compiler-language-typescript.
Great, thanks! Using es2015 and babel-plugin-transform-es2015-modules-commonjs
solved my problems like a charm. The additions to README are helpful, although it might save some hours for people to mention/link to the specific plugin?
Thanks for your help!
from relay-compiler-language-typescript.
Good point, done π
from relay-compiler-language-typescript.
Related Issues (20)
- Generated refetch definition with variables can not pass the validation of backend, such as github.com/vektah/gqlparser/v2
- Generate GraphQL fragment files for VSCode GraphQL Extension fragment autocompletion HOT 2
- Cannot read property 'createKeywordTypeNode' of undefined HOT 8
- Support for [email protected] HOT 8
- Migrate travis CI release process to GitHub actions HOT 3
- Unknown directive 'appendNode' HOT 1
- module esnext HOT 2
- Why is it not releasing HOT 7
- `require` substitution is not working HOT 6
- doc: explain why configuration with a single artifact directory is suggested
- Update to TS 4.4 and update types to support exactOptionalPropertyTypes HOT 1
- @stream argument naming by schema spec is: `initialCount` not `initial_count` HOT 1
- Invalid AST Node error with graphql@16 HOT 2
- Typescript 4.5 type generation is broken HOT 6
- Relay Compiler generates Typescript Synthax error HOT 3
- Error: Cannot find module 'relay-compiler-language-typescript' on 15.0
- Fragment Typematching
- Input Types generated as readonly HOT 1
- deprecate this package HOT 1
- Issue with import of the __generated__
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. πππ
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from relay-compiler-language-typescript.