尝试 使用在我的 Node.js 环境中运行的chrome puppeteer渲染一个 react 组件,我遇到了以下问题:
element让我进入无头 chrome控制台:console.log(element)=><div id="test-wrapper"></div>testWrapper在终端console.log(testWrapper)=>{}
puppeteer.launch().then(async browser => {
const page = await browser.newPage();
const testDocumentPath = path.resolve('./lib/components/util/testDocument.html');
await page.goto(`file://${testDocumentPath}`);
const testWrapper = await page.evaluate((selector) => {
const element = document.querySelector(selector);
console.log(element);
return element;
}, '#test-wrapper');
console.log(testWrapper);
});
Run Code Online (Sandbox Code Playgroud)所以试图做...
ReactDOM.render(
<div>{':)'}</div>,
testWrapper
);
Run Code Online (Sandbox Code Playgroud)
……显然会导致错误 (node:90555) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): Invariant Violation: _registerComponent(...): Target container is not a …