我想將我的 React 應用程式部署到 github,我運行以下命令:
npm run deploy
但我不斷收到此錯誤訊息:
Module build failed: SyntaxError: 'import' and 'export' may only appear at the top level (3:4)
1 | const reportWebVitals = onPerfEntry => {
2 | if (onPerfEntry && onPerfEntry instanceof Function) {
> 3 | import('web-vitals').then(({ getCLS, getFID, getFCP, getLCP, getTTFB }) => {
| ^
4 | getCLS(onPerfEntry);
5 | getFID(onPerfEntry);
6 | getFCP(onPerfEntry);
你能幫我解決這個問題嗎?
uj5u.com熱心網友回復:
它已經告訴你錯誤是什么
'import' 和 'export' 可能只出現在頂層
你可以做什么:
import {getLCP, getFID, getCLS} from 'web-vitals';
getLCP.then(...your code)
uj5u.com熱心網友回復:
您必須使用import的函式/方法,top of the file然后使用它。
import {getCLS, getFID, getLCP} from 'web-vitals';
你可以在這里閱讀檔案
然后用作
const reportWebVitals = (onPerfEntry) => {
if (onPerfEntry && onPerfEntry instanceof Function) {
getCLS(onPerfEntry);
getFID(onPerfEntry);
getFCP(onPerfEntry);
}
};
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/349749.html
