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.

<script setup> not working on root component in production build

See original GitHub issue

Version

4.5.11

Environment info

System:
    OS: Windows 10 10.0.19041
    CPU: (4) x64 Intel(R) Core(TM) i5-6600K CPU @ 3.50GHz
  Binaries:
    Node: 15.7.0 - C:\Program Files\nodejs\node.EXE
    Yarn: Not Found
    npm: 7.4.3 - C:\Program Files\nodejs\npm.CMD
  Browsers:
    Chrome: Not Found
    Edge: Spartan (44.19041.423.0), Chromium (88.0.705.68)
  npmGlobalPackages:
    @vue/cli: Not Found

Steps to reproduce

Create new project with vue create testing (select vue3)

In App.vue change <script></script> block to

<script setup>
/* eslint-disable */
import HelloWorld from "./components/HelloWorld.vue";
</script>

works: Run: npm run serve -> Everything works as expected;

does not work: Run: npm run build Serve dist directory (e.g. http-server) -> nothing gets rendered

What is expected?

Render App

What is actually happening?

App does not get rendered


I somehow have the feeling, that this was working before. This is only happening on the root App component. When I look the imported object, I don’t see any render function.

Cheers!

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:6
  • Comments:15 (4 by maintainers)

github_iconTop GitHub Comments

4reactions
suyingtaocommented, Jul 15, 2021

run:

$ yarn add vue-loader --dev

can solve.

https://github.com/vuejs/vue-loader/issues/1838

4reactions
anmilleriiicommented, Jun 10, 2021

I have also encountered this issue, but not just for the root component (with all SFCs).

I have not traced the cause, but a (verbose) workaround that has worked for me is to append a manual export of the setup() method to SFCs which use the <script setup> syntax.

In each SFC, append the following after the <script setup> block:

// Component.vue
<script setup>
 ...
</script>

<script>
export default {
    setup() {
        return
    }
}
</script>

Using Vue 3.1.1:

// package.json
{
"vue": "3.1.1",
"@vue/compiler-sfc": "3.1.1"
}

I had actually noted that serving the production dist directory (vue-cli-service serve --mode production) intermittently worked with no change in config/code. I was not yet able to determine why this was the case.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Vue 3 brakes when building for production using Options API ...
*Important note: It only fails when using "vite build" and it does not ... to script setup to augment missing component options like...
Read more >
Vue 3: Support new <script setup> without ref sugar - YouTrack
js plugin would support it. It looks like plugin already supports most of new syntax, only issues I found are: when component is...
Read more >
Understanding the new script setup with (defineProps ... - Netlify
Learn the fundamentals of Vue 3.2 script setup feature with ... But that's not all, we can also import and use components without...
Read more >
How to fix the Whitescreen After a Static Deployment with ...
Loading failed for the <script> with source … ... the root of our problem. Your app does not know it's own location to...
Read more >
Strict Mode - React
StrictMode is a tool for highlighting potential problems in an application. ... are run in development mode only; they do not impact the...
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