簡體   English   中英

疑難解答“不能在模塊外使用 import 語句”

[英]Trouble-shooting “Cannot use import statement outside a module”

我正在嘗試使用 puppeteer 在反應應用程序上進行 e2e 測試。 我更喜歡使用 TypeScript,所以我嘗試從以下開頭的文件開始:

import puppeteer, { Browser, Page } from "puppeteer";

不過,我似乎無法解決此錯誤:

({"Object.<anonymous>":function(module,exports,require,__dirname,__filename,global,jest){import puppeteer from "puppeteer";
                                                                                         ^^^^^^

SyntaxError: Cannot use import statement outside a module

  at Runtime.createScriptFromCode (../node_modules/jest-runtime/build/index.js:1350:14)

我很想學習,但不知道如何解決這個問題。

我不認為 Jest 支持 ES6。 您是否檢查過 Jest 文檔以獲取支持 -> https://jestjs.io/docs/ecmascript-modules

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM