我只是想通过NextJS和aws-ampl来运行一个基本的hello世界,但似乎是我npm安装两个库的那一刻
aws-amplify& AWS-扩增反应的
我发现缺少反应模块' &安培;窗口未定义。
import React from 'react'
import Amplify from 'aws-amplify';
Amplify.configure({
Auth: {
// REQUIRED - Amazon Cognito Identity Pool ID
identityPoolId: 'XX-XXXX-X:XXXXXXXX-XXXX-1234-abcd-1234567890ab',
// REQUIRED - Amazon Cognito Region
region: 'XX-XXXX-X',
// OPTIONAL - Amazon Cognito User Pool ID
userPoolId: 'XX-XXXX-X_abcd1234',
// OPTIONAL - Amazon Cognito Web Client ID
userPoolWebClientId: 'XX-XXXX-X_abcd1234',
}
});
export default class extends React.Component {
static async getInitialProps({ req }) {
const userAgent = req ? req.headers['user-agent'] : navigator.userAgent
return { userAgent }
}
render() {
return (
<div>
Hello World
<style jsx>{`
`}</style>
</div>
)
}
}
答案 0 :(得分:0)
您需要制作某种填充物以避免window is not defined
错误。也许您需要检查node_modules
文件夹以查看是否正确安装了react
。
polyfill示例: ```
(<any>global).window = (<any>global).window || {};
(<any>global).localStorage = (<any>global).localStorage || {
store: {},
getItem(key){
if (this.store[key]) {
return this.store[key];
}
return null;
},
setItem(key, value){
this.store[key] = value;
},
removeItem(key){ delete this.store[key]; }
};
```
答案 1 :(得分:0)
尝试一下。安装tslib,然后测试
npm安装tslib