-
-
Notifications
You must be signed in to change notification settings - Fork 433
An example of this working with Babel/ES6, Webpack, HMR, Typescript would be super helpful:) #101
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
Comments
And SASS too would be great;) |
Hi, you might find this a useful reference: https://github.com/Microsoft/TypeScriptSamples/tree/master/es6-babel-react-flux-karma |
Not a problem! I would love to get an example going like you mentioned (it's the long term goal of my blog post series). However, I honestly don't see having the time to get all of that done anytime soon. I can give you a few tips though. Regarding the error you're seeing, it looks like Babel isn't transforming your source for some reason. I honestly don't know why that would be. Is it possible Babel is configured elsewhere to not do certain transformations? Regarding an example with hot reloading, https://github.com/keokilee/react-typescript-boilerplate recently made some rounds on twitter. It's using the new pattern for hot reloading (using a Babel transform instead of |
Thank you both! I will take a look at these and report my findings :) 👍 |
There is a lot of great information in both of the examples you shared. I made some progress incorporating a couple practices such as referencing the tsd and modifications to my tsconfig. At this point I am getting the dreaded invalid token error using this code, although I seem to be getting a new error that I am unsure of. ./app.tsx /// <reference path="../../../typings/tsd.d.ts" />
import * as React from 'react';
import * as ReactDOM from 'react-dom';
import * as App from './components/app/App';
ReactDOM.render(<App />, document.getElementById('app')); ./components/App/App.tsx /// <reference path="../../../../../typings/tsd.d.ts" />
import * as React from 'react';
export default class App extends React.Component<{}, {}> {
public render(): React.ReactElement<{}> {
return (<div>
HELLO WORLD
</div>
);
}
} Which is throwing: [1] ERROR in ./src/global/client/app.tsx
[1] (7,18): error TS2604: JSX element type 'App' does not have any construct or call signatures.
[1]
[1] ERROR in ./src/global/client/app.tsx
[1] Module build failed: SyntaxError: /myprojectname/node_modules/ts-loader/index.js!/myprojectname/src/global/client/app.tsx: Unexpected token (4:16)
[1] 2 | import * as ReactDOM from 'react-dom';
[1] 3 | import * as App from './components/app/App';
[1] > 4 | ReactDOM.render(<App />, document.getElementById('app')); Also something to note is that when I change my tsconfig.json from |
I notice you're using React-DOM which implies that you're using React 0.14.x. To my knowledge the latest typings for React on Definitely Typed are 13.3. I think @jbrantly is working on the 0.14.x Typings at present. This might be throwing you for a loop in the meantime.. |
Thanks for that catch! I will keep my eye out for DefinitelyTyped/DefinitelyTyped#6205 |
You have export default class App And you import it as (which is wrong): import * as App from './components/app/App'; default imports should be done as Note : your IDE should already be highlighting this as an error. If not give atom-typescript a go :P (shameless plug 🌹) PS: Personally I highly dislike |
Thank you @basarat, yes this solved my problem. However if I try to do: export class App extends React.Component<{}, {}> {
public render(): React.ReactElement<{}> {
return (<div>
HELLO WORLD
</div>
);
}
} I still get the error with |
Unlikely. If you have
Error message please. 🌹 |
My mistake:) It is working without /// <reference path="../../../typings/tsd.d.ts" />
import * as React from 'react';
import * as ReactDOM from 'react-dom';
import { App } from './components/app/App';
ReactDOM.render(<App />, document.getElementById('app')); ./components/App/App/App.tsx /// <reference path="../../../../../typings/tsd.d.ts" />
import * as React from 'react';
export class App extends React.Component<{}, {}> {
public render(): React.ReactElement<{}> {
return (<div>
HELLO WORLD
</div>
);
}
} Now all I am getting is the jsx token issue. [1] ERROR in ./src/global/client/app.tsx
[1] Module build failed: SyntaxError: /myprojectname/node_modules/ts-loader/index.js!/myprojectname/src/global/client/app.tsx: Unexpected token (4:16)
[1] 2 | import * as ReactDOM from 'react-dom';
[1] 3 | import { App } from './components/app/App';
[1] > 4 | ReactDOM.render(<App />, document.getElementById('app'));
[1] | ^
[1] 5 | |
Figured I would note that I do have working (with the exception of HMR), the ability to compile successfully by bypassing the babel-loader. By changing the following: {
"compilerOptions": {
"target": "ES5",
"jsx": "react"
},
"exclude": ["node_modules", "config", "dev_server.js"]
} webpack config {
test: /\.ts(x?)$/,
loader: 'react-hot!ts-loader',
exclude: /node_modules/
} I'm now curious why the HMR isn't working as it would seem to be more efficient to bypass the babel transform step? From what I am seeing so far, HMR isn't supported yet. Also including the babel loader and going to es5 with jsx as react works error free but again doesn't enable HMR functionality. |
Destructuring is, in my opinon, the most addictive part of ES6. Looked weird when I first saw it, now I can't stop using it! ❤️ |
Forgive my deliberate repetition. I am trying to record this info so I make sure I'm not repeating my work:) So here's where I am at currently:
To clarify 1 and 2 above, if I edit my [Warning] [HMR] The following modules couldn't be hot updated: (They would need a full reload!)
[Warning] [HMR] - 66 Which points to: [1] [66] ./src/global/client/app.tsx 1.57 kB {0} [built] So I'm left with the existing questions/tasks.
|
I have had trouble in the past with getting // webpack.config.js
module.exports = {
...
babel: {
...
}
}
Not sure, I'm not really familiar with
From my own experience, this would be the way to go. Just use Babel 5 for now, and once |
Just a minor point: there's a problem with sourcemaps in Babel 6. As @jbrantly says stick with 5 for now. It can be tracked here: |
Having done Node Knockout this weekend, there were more than a few instances where HMR would stop working for whatever reason. I'll have to set aside some time to investigate further. |
So... I can't go back down to Babel 5 because I'm also using Hapi with hapi-react-views that has a version that requires Babel 6 if you are using React .14 👊 So I wait patiently as I continue to: |
@keokilee Definitely interested in any cases like that. I'm only aware of one issue related to hot reloading which is documented in #52. For the most part hot reloading issues have less to do with the TypeScript loader and more to do with other aspects of the process. There is a lot that has to go right to get hot reloading working, and a lot depends on what you're trying to hot reload (for instance, a React component vs a helper library) and even what you're changing within that thing (for instance, React's |
A little off topic, but anyone compared with awesome-typescript-loader? Also if anyone can suggest a place to understand a good process for pulling in external libs for React (such and react-slick) into Typescript projects, i'd be eternally grateful:) @jbrantly sorry for spamming you :/ |
Got an example working there https://github.com/Keats/flow-typescript/tree/master/typescript if people want another example |
I have a working boilerplate that is still WIP https://github.com/alexgorbatchev/gulp-typescript-webpack-react-hotreload |
My example has now been updated to Babel 6 following the fix. |
FYI I've added the examples/boilerplates from this thread to https://github.com/TypeStrong/ts-loader/wiki/Tutorials-&-Examples and linked it from the README I'm going to close this thread since I don't believe there are any open items in it (it kind of wondered a bit). If I'm mistaken please feel to open new issues. |
I've been combing through the repo, the issues, and your blog posts and I seem to be missing something here so forgive the rudimentary "issue" == support. Because there are so many moving parts to this tooling setup, it's harder for people to get up to speed with this and I could use a bit of help which hopefully might help the next person:) Currently in my setup I have the following:
Webpack config taking out react-hot doesn't seem to help.
tsconfig.json
app.jsx (my facade - Note it is in regular es6 jsx)
My App component in .tsx in ./components/App/App
And I am still getting the error:
The text was updated successfully, but these errors were encountered: