question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Fix `vue-template-compiler` dependency

See original GitHub issue

Describe the bug

In my project, I’m using "astro": "^1.0.0-beta.17" and "@builder.io/mitosis": "^0.0.49".

There are some errors when installing dependencies in my project and when running Mitosis code, as I’ll explain below.

First suggestion

When running `npm install` (with npm >= v7), these errors are printed:
npm ERR! code ERESOLVE
npm ERR! ERESOLVE could not resolve
npm ERR! 
npm ERR! While resolving: mobx-react-lite@3.3.0
npm ERR! Found: react@18.0.0
npm ERR! node_modules/react
npm ERR!   dev react@"^17.0.2 || ^18.0.0" from the root project
npm ERR!   peer react@"^17.0.2 || ^18.0.0" from @astrojs/react@0.1.1
npm ERR!   node_modules/@astrojs/react
npm ERR!     dev @astrojs/react@"^0.1.1" from the root project
npm ERR!   3 more (@emotion/core, @emotion/react, react-dom)
npm ERR! 
npm ERR! Could not resolve dependency:
npm ERR! peer react@"^16.8.0 || ^17" from mobx-react-lite@3.3.0
npm ERR! node_modules/mobx-react-lite
npm ERR!   dev mobx-react-lite@"^3.3.0" from the root project
npm ERR! 
npm ERR! Conflicting peer dependency: react@17.0.2
npm ERR! node_modules/react
npm ERR!   peer react@"^16.8.0 || ^17" from mobx-react-lite@3.3.0
npm ERR!   node_modules/mobx-react-lite
npm ERR!     dev mobx-react-lite@"^3.3.0" from the root project
npm ERR! 
npm ERR! Fix the upstream dependency conflict, or retry
npm ERR! this command with --force, or --legacy-peer-deps
npm ERR! to accept an incorrect (and potentially broken) dependency resolution.
npm ERR! 
npm ERR! See /Users/gaudel/.npm/eresolve-report.txt for a full report.

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/gaudel/.npm/_logs/2022-05-01T22_15_52_505Z-debug-0.log

The solution to the error above is to install with the following command:

npm install --legacy-peer-deps

It appears that this error is caused by mobx-react-lite not yet supporting React 18. It would be very nice (for me at least, some might consider it slightly more complicated) if Mitosis could use mobx-react-lite as a peer dependency, and require that the user of Mitosis that want to use Mobx, also install that library.

Second suggestion

But after the dependencies are installed, there is another error that require manual intervention, because vue-template-compiler tries to detect if there is a vue package installed with a mismatching version, and if so, it immediately panics and prevents any code that uses it (like mitosis) to run.

I have to manually make this change (monkey patch):

/node_modules/vue-template-compiler/index.js:

 try {
   var vueVersion = require('vue').version
 } catch (e) {}

 var packageName = require('./package.json').name
 var packageVersion = require('./package.json').version
-if (vueVersion && vueVersion !== packageVersion) {
+if (false && vueVersion && vueVersion !== packageVersion) {
   var vuePath = require.resolve('vue')
   var packagePath = require.resolve('./package.json')
   throw new Error(
     '\n\nVue packages version mismatch:\n\n' +
     '- vue@' + vueVersion + ' (' + vuePath + ')\n' +
     '- ' + packageName + '@' + packageVersion + ' (' + packagePath + ')\n\n' +
     'This may cause things to work incorrectly. Make sure to use the same version for both.\n' +
     'If you are using vue-loader@>=10.0, simply update vue-template-compiler.\n' +
     'If you are using vue-loader@<10.0 or vueify, re-installing vue-loader/vueify should bump ' + packageName + ' to the latest.\n'
   )
 }

 module.exports = require('./build')

Maybe we could make the same change as above and make vue-template-compiler a peer dependency ? So the user only installs it if he wants to compile Mitosis to Vue ? I clearly don’t know enough of the repo to know if this is a good strategy.

I did a search in this repo, and it looks that the vue-template-compiler is only called in the cli package. But I’m only using the core package, not the cli, but still the vue-template-compiler package is a dependency of the core package. Can it be safely removed from the core ? EDIT: Now I see it, the Liquid parser is using this package inside core.

I don’t know what is a good solution here, I’m just trying to explain my thought process. Please enlighten me.

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:7 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
samijabercommented, Sep 9, 2022

For reference, our SDKs project is at https://github.com/BuilderIO/builder/tree/main/packages/sdks if you want to look at an example of a project working with Mitosis

0reactions
rhenglescommented, Sep 9, 2022

Yes, I’m using npm v8 in my project, but I appreciate your attention and patience 😁

Read more comments on GitHub >

github_iconTop Results From Across the Web

[vue-loader] vue-template-compiler must be installed as a ...
[vue-loader] vue-template-compiler must be installed as a peer dependency, or a compatible compiler implementation must be passed via options. #3.
Read more >
vue-template-compiler - npm
This package can be used to pre-compile Vue 2.0 templates into render functions to avoid runtime-compilation overhead and CSP restrictions.
Read more >
How do I fix a "Vue packages version mismatch" error on ...
This worked for me: Modify package.json : “vue”: “^2.0.8", “vue-template-compiler”: “^2.1.8". Delete node_modules. Run npm install.
Read more >
Fixing "[vue-loader] vue-template-compiler must be installed ...
Solution: After some searching of GitHub and stackoverflow, it turns out that The vue and vue-template-compiler module version must be the ...
Read more >
ERROR vue-template-compiler must be installed as a peer ...
Error: [vue-loader] vue-template-compiler must be installed as a peer dependency, or a compatible compiler implementation must be passed via options.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found