Static GitHub Issues

[3319] How nuxt loads some static JS libraries?

prev: nuxt is not true ssr?
next: cannot run wget http://localhost:3000 inside a docker container

Version

v1.4.0

Reproduction link

https://jsfiddle.net/Lucu3epf/

Steps to reproduce

  1. Create a self-running script stored in a static JS library
  2. Call this JS library on the page
  3. Refresh the page and throw an exception
// assets/scripts/utils.js
export const u = navigator.userAgent

// pages/index.vue
<template>
  <h1>Error: navigator is not defined</h1>
</template>

<script>
    import { u } from '../assets/scripts/utils' // Error: navigator is not defined

    export default {
        created () {
            if (process.client) {
                console.log(u)
            }
        }
    }
</script>

nuxt template: nuxt-community/starter-template

What is expected ?

I think I need a solution that can use the JS library normally.

What is actually happening?

It should be pre-referenced, and for the first time it is the reason to render through the server.

Additional comments?

Sorry, my English is not very good. I took advantage of Google Translate.

<!--cmty--><!--cmty_prevent_hook--><div align="right"><sub><em>This bug report is available on <a href="https://nuxtjs.cmty.io">Nuxt.js</a> community (<a href="https://nuxtjs.cmty.io/nuxt/nuxt.js/issues/c7049">#c7049</a>)</em></sub></div>