簡體   English   中英

Webstorm意外令牌導出

[英]Webstorm Unexpected Token export

我在Webstorm中遇到了“意外的令牌導出”問題,其他StackOverflow帖子尚未解決。 基本上我正在嘗試使用下面的package.json和bar.js代碼導入/導出模塊功能。 我正在使用Node.js 5x,Babel 6,我有一個File Watcher設置來動態進行Babel轉換。

代碼應該說明一切,我很欣賞有關如何解決它的任何想法。 再次,我已經嘗試了其他StackOverflow建議,此時沒有運氣。

//bar.js

'use strict';

export class Bar{
    constructor(){
        this.tempish = 'allo';
    }
}

//bar-compiled.js

'use strict';

Object.defineProperty(exports, "__esModule", {
    value: true
});

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

var Bar = exports.Bar = function Bar() {
    _classCallCheck(this, Bar);

    this.tempish = 'allo';
};

//# sourceMappingURL=bar-compiled.js.map

//index.js

'use strict';

import {Bar} from './bar'

console.log('This is a test.');

//index-compiled.js

'use strict';

var _bar = require('./bar');

console.log('This is a test.');

//# sourceMappingURL=index-compiled.js.map

//package.json

{
  "name": "npt-test",
  "version": "1.0.0",
  "description": "",
  "main": "index-compiled.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "",
  "license": "ISC",
  "dependencies": {
    "babel": "^6.3.26",
    "babel-cli": "^6.4.5",
    "babel-core": "^6.4.5",
    "babel-plugin-transform-decorators-legacy": "^1.3.4",
    "babel-preset-es2015": "^6.3.13",
    "babel-preset-stage-0": "^6.3.13"
  }
}

//.babelrc

{
    "presets": ["es2015", "stage-0", "stage-1"],
    "plugins": ["babel-plugin-transform-decorators-legacy"]
}

//Error on debug, I am running against the index-compiled.js during debug

C:\Program Files (x86)\JetBrains\WebStorm 11.0.3\bin\runnerw.exe"
"C:\Program Files\nodejs\node.exe" --debug-brk=45287 --nolazy index-compiled.js
Debugger listening on port 45287
[MYPROJECTDIR]\bar.js:3
export class Bar{
^^^^^^

SyntaxError: Unexpected token export
    at exports.runInThisContext (vm.js:53:16)
    at Module._compile (module.js:373:25)
    at Object.Module._extensions..js (module.js:404:10)
    at Module.load (module.js:343:32)
    at Function.Module._load (module.js:300:12)
    at Module.require (module.js:353:17)
    at require (internal/module.js:12:17)
    at Object.<anonymous> ([MYPROJECTDIR]\index-compiled.js:3:12)
at Module._compile (module.js:397:26)
at Object.Module._extensions..js (module.js:404:10)

進程以退出代碼1結束

你的index-compiled.js代碼是什么樣的? 似乎它需要原始的bar.js而不是bar-compiled.js Node.js本身不能執行ES6代碼,因此錯誤。

我建議配置編譯器將轉換后的代碼輸出到一個單獨的目錄中,以避免使用'編譯'后綴。 有關使用WebStorm設置Babel 6的說明,請參閱以下鏈接: http ://mcculloughwebservices.com/2015/12/10/webstorm-b​​abel-6-plugin/

暫無
暫無

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

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