-
Notifications
You must be signed in to change notification settings - Fork 64
SyntaxError: 'import' and 'export' may appear only with 'sourceType: module' (1:0) #33
Comments
try this: loader: 'istanbul-instrumenter',
query: {
esModules: true
} |
I have just updated readme with a special note about |
ok thank you very much :). Now i get this
Any idea ? :) |
hmm, try to comment out everything related to coverage – it looks like you should to transpile some additional folder or files, because ES6 code gets in PhantomJS as is. |
What do you mean ? Sorry i tried so many things, i don't visualize what i have to remove or comment with the karma config. |
remove the whole block: postLoaders: [{
test: /\.js/,
include: path.resolve('lib/'),
exclude: /(node_modules)/,
loader: 'istanbul-instrumenter'
}] and reporters: ['spec', 'coverage'], and include {
test: /\.js$/,
exclude: [
path.resolve('lib/'),
path.resolve('node_modules/')
],
loaders: ['babel']
} and give it a try, run your tests without coverage. it looks like your issue is not related to |
I tried like this:
No error and my two tests files successful |
weird... do you have any public repo with this so I can reproduce it by myself? |
Yes of course, i updated the repo like that, you can try: |
@kevincaradant thanks, I got it. @DatenMetzgerX just realized that the instrumented code is not transpiled at all o_O
note:
does this mean that we have to transpile it with babel-loader after instrumentation step?.. I thought that it works the same way as isparta does, i.e. transpiling + instrumentation. |
@DatenMetzgerX just looked at source code:
but if after these steps I need to transpile it to ES5 with Babel, how this |
that's why we have #29... looks like https://github.com/istanbuljs/babel-plugin-istanbul is a simpler solution at this moment. |
The babel-plugin does exactly the same as the loader does. Sorry, I'm still at a Hacketon, so I don't really have time to look into it. Will come back to you soon. |
yes but babel-plugin-istanbul works as a part transpiling process by directly using its "visitor" by Babel, so they don't need to support input SourceMaps and subsequent remapping. as far as I understand what we need here for now:
|
The very more important part is, that babel does no bundling. Therefore, for each file there is one output (input -> output). But currently there exist no solution to do so when using a bundler (all PRs are still pending) |
and I still can't get how exactly karma-coverage will generate a report for original ES6 lines and columns. if my tests requires transpiled source code then |
I tried to explain it in istanbuljs-archived-repos/istanbul-lib-source-maps#4 |
am I understanding it right that istanbul-lib-instrument will remap these parts |
which counters? istanbul-lib-instrument does not perform any remapping at it's own. But the line numbers created by lib istanbul reference the line numbers of the input source (in case of a transpiled input from typescript, those are the line numbers of the transpiled source code and not the original ones...) When generating the reports, then istanbul-lib-sourcemap-support uses the sourcemap included in the file (if 1:1 mapping between input and output source) or - the version of my pull requests - uses the sourcemap included in the coverage information to map the line numbers back to the original code (transpiled line numbers back to original line numbers). This is also possible if remap-istanbul is used. The old istanbul version is not capable to perform this remapping, but loads the original source code. Therefore it tries to highlight branches / lines that are not existing in the original source code, but are in the transpiled.... My working setup is the following (It's a little bit complicated, as non of my pull requests got merged so far). My build chain uses typescript -> babel -> istanbul and karma for running the tests.
remap-istanbul --input ./coverage/Firefox*/coverage-final.json --output ./coverage/html -t html && remap-istanbul --input ./coverage/Firefox*/coverage-final.json --output ./coverage/lcov.info -t lcovonly The setup is used quite successfully in my student project parallel.es (the only setup i found that is capable to create the coverage over typescript source that actually works if webpack is used) I hope this helps |
ok, after deep digging into the problem and fixing my start-istanbul (look at these "hacky" singletons to share @DatenMetzgerX your solution proposed in istanbuljs-archived-repos/istanbul-lib-instrument#23 + istanbuljs-archived-repos/istanbul-lib-source-maps#4 looks legit, in my opinion coverage object is ok to store the original source map in it. I didn't look in detail in karma-runner/karma-coverage#251 yet, just hope that your PR will contain remapping of coverage map. @kevincaradant sorry for involving you in this :) the bottom line: we are waiting for at least 3 PRs to be merged to just be able to show you coverage over original sources. |
@kevincaradant you can use https://github.com/deepsweet/isparta-loader or https://github.com/deepsweet/babel-istanbul-loader for a while, I just undeprecated them. |
No problem :) I tried https://github.com/deepsweet/isparta-loader. My karma.config.js becomes:
Do you see something wrong ? Ah also this is my tests.webpack.js as you suggested like only point of entry:
But I'm not sure about my regex for the components :/. My tests and others files are in the same location but the only diff is that the tests files are named : But i thought that at the end I should have all files and not only this : I have two files *.spec.js which are home and page1. Do you an idea to have others files with 0% coverage ? PS: Look at my repo if you want something about the files structures or anything else ;) |
aaand there you go #15 |
Thnaks @deepsweet :). Mhh what is the good answer ? I don't know what I have to try finally ? :/ |
unfortunately there is no good answer, that's the way how Istanbul works. you have to somehow require all the sources to get 0% coverage listing even if there are no tests for them. |
just to be more clear: istanbul-instrumenter-loader will instrument (i.e. there will be some coverage) only those files that were required by 1. some test(s) 2. you. |
Hi This issue can be closed or not yet ? Just to know, no pressure ;) |
I think we should close the issue. The karma-coverage pull request is not going to be merged any time soon as they expect a feature complete pull request instead. Furthermore, I currently lack the time and knowledge to work on it any further... |
Getting SyntaxError: 'import' and 'export' may appear only with 'sourceType: module', If I comment all the code in webpact.test.conf related to istanbul-instrumenter-loader' there is no error and I tried using esModule comipler option in the same file I believe the following are the relevant files, please take a look:
|
Why are you running the loader as a pre step on typescript files? The istanbul loader can not handle typescript as input, only js. So change it to a post loader instead of pre loader and test if this works. The loader should run as post loader. Furthermore, you need to specify |
Apologies for not putting the updated code, I changed my description but forgot to change the code. I already tried all the steps and have updated the code too, by the @deepsweet mentions esModules and singular esModule, but I tried both and same error |
@khanharis87 have you tried Matt Lewis's [karma-coverage-istanbul-reporter][https://github.com/mattlewis92/karma-coverage-istanbul-reporter] with |
Thanks! I got it running using the following configuration inside of my karma.conf.js file:
|
try this: Where exactly (at what level, which property?) does this go? My legacy config has two references to Istanbul, one with typescript. Thanks much. |
Hi
I want to coverage all files and not only the tests. So I excluded the node_moduels folder. But i get this error on all the others files.
WARNING in ./lib/components/home/home.config.js
Module build failed: SyntaxError: 'import' and 'export' may appear only with 'sourceType: module' (1:0)
at Parser.pp.raise (C:\Users\kevin\Documents\Projets\web-template-webpack\node_modules\babylon\lib\parser\location.js:22:13)
This is my karma.config.js:
this is my tests.webpack.js:
Example of home.config.js:
What's wrong ? Thank you :)
The text was updated successfully, but these errors were encountered: