Skip to content
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

Unexpected token '*' #13

Open
justdigitalsugar opened this issue Jun 14, 2023 · 4 comments
Open

Unexpected token '*' #13

justdigitalsugar opened this issue Jun 14, 2023 · 4 comments

Comments

@justdigitalsugar
Copy link

I am getting a console error when running a build. Everything compiles and live reload works as it should in dev, but as soon as I go into production none of the styles compile and I get this console error

Uncaught SyntaxError: Unexpected token '*' (at main-3fb20dfd.css?ver=6.2.2:1:1)

I am on a Windows computer if this makes any difference. Relatively new to all this!

@guugg
Copy link

guugg commented Jun 15, 2023

Should be the same problem

#10

@nikolailehbrink
Copy link

Same problem here @blonestar. Would be nice, if you could fix this. It tries to load the css via script.

Here are the steps I did:

  1. Changed wp-config todefine('IS_VITE_DEVELOPMENT', false);
  2. run npm build
  3. Got the above mentioned error in the console and the following warning on the site (and no css is loaded): Warning: foreach() argument must be of type array|object, null given in /Users/nikolai/Local Sites/vite/app/public/wp-content/themes/wp-theme-vite-tailwind/inc/inc.vite.php on line 55
  4. Tried to debug, how the css file is inserted in the html and noticed the following line:
<script type="text/javascript" src="https://vite.local/wp-content/themes/wp-theme-vite-tailwind/dist/assets/main-cb65a5b9.css?ver=6.2.2" id="main-js"></script>

Bildschirm­foto 2023-06-20 um 12 48 40

@zawzawzaw
Copy link

zawzawzaw commented Jun 30, 2023

For this error on production mode, I fixed it by changing it like below, problem was because it was reading the wrong json value from the manifest file.

`// enqueue hook
add_action( 'wp_enqueue_scripts', function() {

if (defined('IS_VITE_DEVELOPMENT') && IS_VITE_DEVELOPMENT === true) {

    // insert hmr into head for live reload
    function vite_head_module_hook() {
        echo '<script type="module" crossorigin src="' . VITE_SERVER . VITE_ENTRY_POINT . '"></script>';
    }
    add_action('wp_head', 'vite_head_module_hook');        

} else {

    // production version, 'npm run build' must be executed in order to generate assets
    // ----------

    // read manifest.json to figure out what to enqueue
    $manifest = json_decode( file_get_contents( DIST_PATH . '/manifest.json'), true );
    
    // is ok
    if (is_array($manifest)) {
            
        // enqueue CSS files
        $css_file = $manifest['main.css']['file'];
        if ( ! empty($css_file)) {
            wp_enqueue_style( 'main', DIST_URI . '/' . $css_file );
        }
        
        // enqueue main JS file
        $js_file = $manifest['main.js']['file'];
        if ( ! empty($js_file)) {
            wp_enqueue_script( 'main', DIST_URI . '/' . $js_file, JS_DEPENDENCY, '', JS_LOAD_IN_FOOTER );
        }

    }

}

});`

@ineptian
Copy link

Seems like this fix should be merged asap.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants