![](/img/trans.png)
[英]Uncaught SyntaxError: Cannot use import statement outside a module for React
[英]SyntaxError: Cannot use import statement outside a module React JS Antd
為了優化包大小而不是從 lib 文件夾中獲取組件,我從 es 文件夾中導入它。
例子:
import Modal from 'antd/es/modal';
所以在編寫測試用例時它給了我以下錯誤
SyntaxError: 不能在模塊外使用 import 語句
我已經解決了可能重復的相關問題,但由於它不屬於全局 scope ,因此無法用我當前的實現解決它。
所以我的問題是,有沒有辦法實現這一點
我也嘗試參考以下鏈接但沒有幫助,
https://github.com/reactstrap/reactstrap/blob/master/package.json#L21 https://medium.com/@fredriccliver/syntaxerror-cannot-use-import-statement-outside-a-cmodule-statement-outside-a-cmodule-699
改變
import frFR from 'antd/es/locale/fr_FR';
至
import frFR from 'antd/lib/locale/fr_FR';
解決這個問題。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.