Probably not compiling with babel: `Unexpected import token`
See original GitHub issueDescription
Testings are failing in Unexpected import token
(probably due to non babel compiling issue)
Test Source
initials.js
const initials = (string: string) =>
string.split(' ').map(word => word[0]).join('').slice(0, 2);
export default initials;
initials.test.js
import test from 'ava';
import initials from './initials';
test(t => t.expect(initials('Renato Ribeiro')).toBe('RR'));
Error Message & Stack Trace
Here’s a print (Sorry, I have a problem with my term that I can’t copy text 😢)
Config
package.json
{
"...": "...",
"ava": {
"babel": "inherit"
}
}
.babelrc
{
"presets": [
"next/babel"
],
"plugins": [
"transform-export-extensions"
]
}
Note: also tested with "require": ["babel-register"]
in ava configuration
Command-Line Arguments
ava
Relevant Links
Repo: https://github.com/renatorib/next-jsonplaceholder Initials test commit: https://github.com/renatorib/next-jsonplaceholder/commit/f5602a1f77163ca9a0fdac4f9bd76ccf10955fcd
Environment
$ ava --version
0.18.2
$ node --version
v7.5.0
Issue Analytics
- State:
- Created 7 years ago
- Reactions:6
- Comments:7 (5 by maintainers)
Top Results From Across the Web
"unexpected token import" in Nodejs5 and babel?
For me it was a simple fix. I was caught in tunnel vision trying to adapt code from one react/babel project into another...
Read more >SyntaxError: Unexpected token - JavaScript - MDN Web Docs
The JavaScript exceptions "unexpected token" occur when a specific language construct was expected, but something else was provided.
Read more >How I Fixed The Unexpected Token Error In Jest
I saw it on line 1, because line 1 is almost always occupied by an import statement - and there are no import...
Read more >syntaxerror unexpected token export babel-jest - You.com
This means, that a file is not transformed through TypeScript compiler, e.g. because it is a JS file with TS syntax, or it...
Read more >Import React in Node.js throws SyntaxError - appsloveworld.com
That's because you are transpiling only ./src/server and not ./src/admin . Then in ./src/server you have export keyword not translated by Babel and...
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
Put those to package.json:
Source: transpiling-sources@AVA
@avajs, I would suggest making init more clever so those issues are gone. To be “No extra setup needed.” 😃
I actually get this error, which seems to be some Flow syntax that isn’t removed:
In any case, it means AVA transpiled the ESM syntax correctly.
But does it transpile to CJS?
This issue tracker is for AVA itself. Happy to do the occasional support here, and happy to keep discussing, but this is a problem with your Babel setup, not AVA.