SyntaxError: Unexpected token export (import)
See original GitHub issueDescription
Ava starts to give SyntaxError: Unexpected token export
with babelrc es2015 set to “modules”: false.
Does not happen if modules props is not set.
AND Specifying custom config via ava/babel in package.json does not help.
Webpack uses same config. Babel compiles files successfully if executed manually as
babel ./src/app/actions/constants/shared.js --presets=node6
Error Message & Stack Trace
src/app/actions/constants/shared.js:1
(function (exports, require, module, __filename, __dirname) { export var NOT_STARTED = 'NOT STARTED';
^^^^^^
SyntaxError: Unexpected token export
at Object.exports.runInThisContext (vm.js:76:16)
at Module._compile (module.js:542:28)
at loader (/Users/dlebedynskyi/Documents/Code/code/node_modules/babel-register/lib/node.js:144:5)
at require.extensions.(anonymous function) (/Users/dlebedynskyi/Documents/Code/code/node_modules/babel-register/lib/node.js:154:7)
at extensions.(anonymous function) (/Users/dlebedynskyi/Documents/Code/code/node_modules/require-precompiled/index.js:16:3)
at Object.require.extensions.(anonymous function) [as .js] (/Users/dlebedynskyi/Documents/Code/code/node_modules/ava/lib/process-adapter.js:104:4)
at Module.load (module.js:487:32)
at tryModuleLoad (module.js:446:12)
Config
package.json
:
{
"ava": {
"files": [
"test/**/*.spec.js"
],
"source": [
"src/**/*.{js,jsx}"
],
"concurrency": 5,
"require": [
"babel-register",
"babel-polyfill",
"ignore-styles",
"./test/setup.js"
],
"babel": "inherit"
}
}
.babelrc
{
"plugins": [
"transform-export-extensions",
"transform-class-properties",
["transform-builtin-extend", {
"globals": ["Error"]
}],
["transform-object-rest-spread", {
"useBuiltIns": true
}],
["transform-react-jsx", {
"useBuiltIns": true
}],
["transform-regenerator", {
"async": false
}],
["transform-runtime", {
"helpers": false,
"polyfill": false,
"regenerator": true
}],
"react-hot-loader/babel"
],
"presets": [
"react",
["latest", {
"es2015" : {
"modules": false,
"loose": true
}
}]
]
}
Command-Line Arguments
npm run ava
What I had tried and it did not work
- specify custom babel config in ava section
"ava": {
...
"require": [
"babel-register",
"babel-polyfill",
"ignore-styles",
"./test/setup.js"
],
"babel": { "presets": [ "react", "latest"] }
}
- specify “node6”
"ava": {
...,
"babel": {
"babelrc": false,
"presets": [ "node6" ]
}
},
- Try use extend as https://github.com/avajs/ava/blob/master/docs/recipes/babelrc.md#extend-an-alternate-config-file - same result.
Environment
Node.js v6.9.1
darwin 16.1.0
ava 1.7.0
It looks like test files are being transpired correctly but for source files are ignored 😦.
This happens only with modules:false
. And this is being set so for tree shacking webpack2. To enable common js modules I’ve tried things above an it still looks like .babelrc is used without overrides.
Issue Analytics
- State:
- Created 7 years ago
- Comments:25 (4 by maintainers)
Top Results From Across the Web
Getting Unexpected Token Export - javascript
I solved it by declaring a type as a module when adding a script tag in my index. html file.
Read more >How to fix SyntaxError: Unexpected token 'export' in ...
In this article, we are going to see How to fix SyntaxError: Unexpected token 'export' in JavaScript? and what are Es6 modules.
Read more >SyntaxError: Unexpected token 'export' in JavaScript
To solve the "Uncaught SyntaxError Unexpected token 'export'" error, set the type property to module in your package.json file.
Read more >How to Fix „Uncaught SyntaxError: Unexpected token 'export
It told us that the export keyword isn't available when importing the bundled JavaScript into the browser.
Read more >SyntaxError: Unexpected token export, when import not ...
FAIL src/index.test.js ○ Test suite failed to run Jest encountered an unexpected token This usually means that you are trying to import a...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Where do I set
modules: false
!?modules: false
disables transpiling the module syntax to Node.js’ module system. You’ll need to enable that for AVA to work.