![](/img/trans.png)
[英]Webpack/Babel es2015 error: Uncaught SyntaxError: Unexpected token import
[英]Javascript ES2015 import throws Uncaught SyntaxError: Unexpected token {
我有一個網站托管在Firebase托管上。 我想為其添加素材主題(按鈕,文本字段等)。 因此,我運行了命令npm install --save @material/textfield
。 然后,將名為@material
的文件夾提取到我的樣式目錄中,以便結構如下所示:
Root
|
+---index.html
+---scripts/
+---app.js
+---styles/
+---main.css
+---@material/
+---……
我可以通過添加@import "@material/textfield/dist/mdc.textfield.css";
來引用來自main.css
的CSS文件@import "@material/textfield/dist/mdc.textfield.css";
到我的樣式表的開頭。 這可以正確更改按鈕的樣式。 但是,當我為js做同樣的事情時,它不起作用。
根據Material Design的Github Repo,我應該能夠添加
import {MDCTextField} from '@material/textfield';
const textField = new MDCTextField(document.querySelector('.mdc-text-field'));
到我腳本的頂部。 但是,當我部署代碼並查看控制台時,將返回以下錯誤: Uncaught SyntaxError: Unexpected token {
。 我試圖用require()
文件,並更改import {MDCRipple} from '../styles/@material/ripple/dist/mdc.ripple.js';
的路徑import {MDCRipple} from '../styles/@material/ripple/dist/mdc.ripple.js';
。 這將引發相同的錯誤。 如果我這樣做: import * as MDCRipple from '../styles/@material/ripple/dist/mdc.ripple.js';
,也會引發相同的錯誤(除了代替“ {”字符,它不希望出現“ *”字符)。
對於我的網站來說,這本來應該是一個容易的轉換,但是這讓我頭疼不已。 我究竟做錯了什么?
順便說一句:我知道導入語句正在使用的文件存在。 另外,Node.js不是服務器端嗎?
下載最新版本的節點: https : //nodejs.org/en/
版本8.11.2 LTS可以使用。
--experimental-modules標志可用於啟用ES2015導入功能。 更多信息:
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.