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
Angular 4 + Universal: Window is not defined #134
Comments
Universal support is in progress (just a few little tweaks remain) |
What would be the best way to achieve this? Do you have an example laying around? |
Right now I'm using new DefinePlugin({
window: undefined,
document: undefined,
location: JSON.stringify({
protocol: 'https', // `http` or `https`
host: `your host`,
})
}), |
So I'm using
|
@mchambaud which version of |
1.0.0-beta.7 |
you should remove |
|
can you use my repo to check if it's work in your project "@uirouter/angular": "https://github.com/aitboudad/ng2#f8201c2c368baa759b32e392a1308fc26e09a176", instead of: import {} from @uirouter/angular use: import {} from @uirouter/angular/src |
Ok wil do that right away |
you should target the folder |
When I are you on gitter by any chance? |
can you update package hash and try again "@uirouter/angular": "https://github.com/aitboudad/ng2#a7e3387a7a821c105ce6e8538657d4cd161ed881", |
So! It compiles! But I get window is not defined at runtime.. Do you want to Screenhero or Skype real quick see if it's a stupid mistake on my part? |
My skype is the same as my GitHub username |
Maybe I can help finish @uirouter for Universal. What pending tasks is there? |
@aitboudad shouldn't this be a ui-router/core issue then ? |
Note the base location services class has been updated: ui-router/core@a4629ee#diff-aee9f1b1f04ef087e5d4b8ff17e636fc |
@christopherthielen - Could you please tell me when this fix will be released? |
@aitboudad @christopherthielen I tries to enable server side rendering for my project. But it looks like it's impossible to use @uirouter/angular lib with node.js. I've prepared project using angular-cli guide for server side rendering (https://github.com/angular/angular-cli/wiki/stories-universal-rendering) and tries to build backend code. Build process finishes fine but I got an error when I run backend app:
I use beta-8 version. Could you please tell me is there a way to use ui-router on the backend for now? |
Here is my webpack.config.js: const path = require('path');
const webpack = require('webpack');
const nodeExternals = require('webpack-node-externals');
module.exports = {
entry: { server: './app.ts' },
resolve: { extensions: ['.ts', '.js'] },
resolveLoader: {
modules: [
'./node_modules',
'./node_modules'
]
},
target: 'node',
externals: [
nodeExternals({})
],
output: {
path: path.join(__dirname, 'dist'),
filename: '[name].js',
libraryTarget: 'commonjs'
},
module: {
rules: [
{ test: /\.ts$/, loader: 'ts-loader' },
{ test: /\.json$/, loader: "raw-loader"},
]
},
plugins: [
// Temporary Fix for issue: https://github.com/angular/angular/issues/11580
// for "WARNING Critical dependency: the request of a dependency is an expression"
new webpack.ContextReplacementPlugin(
/(.+)?angular(\\|\/)core(.+)?/,
path.join(__dirname, 'src'), // location of your src
{} // a map of your routes
),
new webpack.ContextReplacementPlugin(
/(.+)?express(\\|\/)(.+)?/,
path.join(__dirname, 'src')
)
]
}; |
I followed the instructions at https://github.com/angular/angular-cli/wiki/stories-universal-rendering and was able to get the UI-Router Sample App working as a universal app. I published it as a branch named angular-universal Here is the relevant commit: ui-router/sample-app-angular@b642962 To try it out, fetch the repository, switch to |
To debug the server-side app, you might want to try |
@christopherthielen Thank you. I've solved my problem. It was related to libs in my backend app. I've excluded it from the result backend bundle with nodeModules webpack extension. |
I think this was fixed in some previous release. Please let me know if it is not. |
Everything works fine using
ng serve
and it compiles fine withngc
but I get the following exception at runtime.this is my app.server.module.ts
Did what #43 said to do but no luck.
The text was updated successfully, but these errors were encountered: