-
Notifications
You must be signed in to change notification settings - Fork 159
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Babel bug: .inputSourceMap must be a boolean, object, or undefined
& filename
is undefined error fix
#138
Conversation
line 14. import vue file containing <script lang="ts"> in tests fails due to "node_modules/@babel/core/lib/config/validation/option-assertions.js:110:11)" line 18: Even though filename is optional as of their typedef() not providing "filename" throws an error in "node_modules/@babel/core/lib/config/config-chain.js:431:11" line 20. It would be nice to upgrade the plugin as well
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the PR, it looks good :)
Can you add a new test that reproduces the issue that's fixed by this change?
Can you please elaborate the steps? As in how/what should I test? |
You could create a test that reproduces the issue. You can see a test here—https://github.com/vuejs/vue-jest/blob/v3/test/Babel.spec.js#L98. It writes plugins to the .babelrc file, then calls |
lib/compilers/babel-compiler.js
Outdated
@@ -1,4 +1,4 @@ | |||
const babel = require('babel-core') | |||
const babel = require('@babel/core') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This makes this PR a breaking change, can you keep the old babel-core in this PR? You can use babel-core bridge (https://github.com/babel/babel-bridge) if you need functionality of babel 7.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reverted back.
Alright, so it was not as easy as I thought it would be. It has to do with babel 7, and the current vue-jest is transpiled with babel 6. Here are the summary of what has been done:
|
#122 should be fixed with this one, along with some other babel 7 related issues which are faced by users |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
bounced back to babel 6 as per review
lib/compilers/babel-compiler.js
Outdated
@@ -1,4 +1,4 @@ | |||
const babel = require('babel-core') | |||
const babel = require('@babel/core') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reverted back.
lib/compilers/babel-compiler.js
Outdated
@@ -23,7 +23,16 @@ module.exports = function compileBabel (scriptContent, inputSourceMap, inlineCon | |||
babelOptions = Object.assign(babelOptions, babelOverWrites) | |||
} | |||
|
|||
const res = babel.transform(scriptContent, babelOptions) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you revert to the previous code? babel.transform will use babel 6 transform if babel-core is babel 6, and babel 7 if babel-core is @bridge.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@eddyerburgh Test provided, snapshot failing. Please check, My test included babel 7, which is why there is snapshot missmatch. |
.inputSourceMap must be a boolean, object, or undefined
.inputSourceMap must be a boolean, object, or undefined
.inputSourceMap must be a boolean, object, or undefined
& filename
is undefined error fix
For anyone who encounters this error too: After several hours I found a fix/workaround for this problem: tsconfig.json: {
"compilerOptions": {
[...]
"allowSyntheticDefaultImports": true, This is the important setting. |
Same error happened to me, and in my case, I solved it by adding |
lib/process.js
Outdated
const vueJestConfig = getVueJestConfig(jestConfig) | ||
|
||
var parts = vueCompiler.parseComponent(src, { pad: true }) | ||
|
||
if (parts.script && parts.script.src) { | ||
parts.script.content = fs.readFileSync(join(filePath, '..', parts.script.src), 'utf8') | ||
} | ||
|
||
const result = processScript(parts.script, vueJestConfig, filePath) | ||
const result = processScript(parts.script, vueJestConfig, filePath, babelTestObj) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you please remove the babelTestObj
from the code
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
test/Babel-typescript.spec.js
Outdated
cache.flushAll() | ||
clearModule.all() | ||
}) | ||
test('babel 7 configuration expects filename [default: "unknown"] to compile', () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In this case, since it's a small change and difficult to test, you can remove these tests and we'll leave it untested
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
So since the changes to code are relatively small, and we'll realase v4 soon, it's OK to add this code without any tests. Can you please put an inline comment above the code to add the filename, and above the ternary where you assign the input map, to describe why you made the changes? |
lib/compilers/babel-compiler.js
Outdated
@@ -17,11 +17,15 @@ module.exports = function compileBabel (scriptContent, inputSourceMap, inlineCon | |||
} | |||
|
|||
const babelOptions = Object.assign(sourceMapOptions, babelConfig) | |||
if (!babelOptions.filename) babelOptions.filename = 'unknown' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you remove this line please
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the changes :)
This has been released in 3.0.3 👍 |
@eddyerburgh - I'm not seeing 3.0.3 on NPM yet. Is there a delay on NPM's side? |
No sorry, the publish had failed on my end. Just published now |
This is my first pull request ever just FYI :) So, Please go easy on me.
Current @babel/core requires either boolean, or object in inputSourceMap. So putting empty string will throw error (lib/compilers/typescript-compiler.js : 14)
While using @babel/preset-typescript babel.transform requires a filename(lib/compilers/babel-compiler.js: 20), even though the typedef for @babel/core says it's optional. I have given the defaultname "unknown" mentioned in the @types/babel-core file
Ran test to make sure it didn't break anything