gatsby: [v2] Typescript plugin not working
Description
I tried to use the typescript plugin with v2 to no avail. I get the following error message.
ERROR in ./src/pages/index.tsx
Module parse failed: Unexpected token (3:7)
You may need an appropriate loader to handle this file type.
| import * as React from 'react';
|
| export interface IndexProps {}
|
| export interface IndexState {}
@ ./.cache/sync-requires.js 11:51-124
@ ./.cache/root.js
@ ./.cache/app.js
@ multi ./node_modules/react-hot-loader/patch.js (webpack)-hot-middleware/client.js?path=http://localhost:8000/__webpack_hmr&reload=true&overlay=false ./.cache/app
ℹ 「wdm」: Failed to compile.
Environment
- Gatsby version (
npm list gatsby): 2.0.0-alpha.40 - gatsby-cli version (
gatsby --version): - Node.js version: 8.9.x
- Operating System: macOS Sierra
File contents (if changed)
gatsby-config.js:
module.exports = {
plugins: [`gatsby-plugin-typescript`, `gatsby-plugin-react-helmet`],
};
package.json: N/A
gatsby-node.js: N/A
gatsby-browser.js: N/A
gatsby-ssr.js: N/A
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Reactions: 3
- Comments: 32 (23 by maintainers)
It works but I had to force the preset to
@babel/preset-typescript 7.0.0-beta.42because7.0.0-beta.49throws the following error:Test repo at https://github.com/dannywils/gatsby-typescript-staticquery/tree/babel
Got
preset-typescriptworking (only tried with babel beta 49) with the following configuration:Here I’m not using
setBabelPreset, since that seems to only affect/.jsx?/files.This is only a quick fix though, since in a more general setup we should somehow be able to pass all the correct arguments to the presets and plugins. For comparison, here’s a simplified version of the default rules for js/jsx parsing:
My guess is that it was to reduce breakage in the babel7 migration, babel6’s react preset included flow. Good question tho as to whether that is still a good idea…