-
Notifications
You must be signed in to change notification settings - Fork 61
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
Prerendering failed because of error: ReferenceError: window is not defined #27
Comments
You should add an alias of "react-wavy-audio" and make it webpack.config.js //...
// Configuration for server-side (prerendering) bundle suitable for running in Node.
const serverBundleConfig = merge(sharedConfig(), {
module: {
rules: [
{ test: /\.(scss|sass)$/, use: "ignore-loader" }
]
},
resolve: {
mainFields: ['main'],
alias: {
'myLibThatNeedsWindow': false // Add this alias to the serverBundleConfig
}
},
entry: { 'main-server': './ClientApp/boot-server.tsx' },
plugins: [
new webpack.DllReferencePlugin({
context: __dirname,
manifest: require('./ClientApp/dist/vendor-manifest.json'),
sourceType: 'commonjs2',
name: './vendor'
})
],
output: {
libraryTarget: 'commonjs',
path: path.join(__dirname, './ClientApp/dist')
},
target: 'node'
});
//... Then wrap any callings of that library into condition MyAwesomeComponent.js import { isNode } from '@Utils';
import myLibThatNeedsWindow from "myLibThatNeedsWindow";
if(!isNode()) {
// Will be ignored by prerendering.
myLibThatNeedsWindow();
} |
Added in webpack.config.js: Throwing the below exception once made the changes as you suggested: **Invalid configuration object. Webpack has been initialised using a configuration object that does not match the API schema.
|
|
Uncaught Invariant Violation: Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: undefined. You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports. Check the render method of |
I have installed the library: npm install react-wavy-audio and this library needs window to be defined, Once I ran the application and getting the below exception in the browser.
Microsoft.AspNetCore.NodeServices.HostingModels.NodeInvocationException: Prerendering failed because of error: ReferenceError: window is not defined
at eval (webpack-internal:///./node_modules/react-wavy-audio/dist/index.js:40:4)
at createCommonjsModule (webpack-internal:///./node_modules/react-wavy-audio/dist/index.js:29:35)
at eval (webpack-internal:///./node_modules/react-wavy-audio/dist/index.js:32:18)
at Object../node_modules/react-wavy-audio/dist/index.js
@NickMaev @XuHaoJun can you please help me out to resolve this exception?
The text was updated successfully, but these errors were encountered: