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

Nuxtjs 3 + vanilla extract build error #413

Closed
rubenmoya opened this issue Oct 14, 2021 · 10 comments
Closed

Nuxtjs 3 + vanilla extract build error #413

rubenmoya opened this issue Oct 14, 2021 · 10 comments

Comments

@rubenmoya
Copy link

Describe the bug

Nuxt 3 beta has been released and I was trying to use vanilla-extrat with it. I installed the vite plugin and added it to the nuxt.config.ts file. After running yarn dev I get this error:

some_folder/node_modules/@vanilla-extract/css/fileScope/dist/vanilla-extract-css-fileScope.esm.js:1
import outdent from 'outdent';
^^^^^^

SyntaxError: Cannot use import statement outside a module
    at wrapSafe (internal/modules/cjs/loader.js:988:16)
    at Module._compile (internal/modules/cjs/loader.js:1036:27)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1101:10)
    at Module.load (internal/modules/cjs/loader.js:937:32)
    at Function.Module._load (internal/modules/cjs/loader.js:778:12)
    at ModuleWrap.<anonymous> (internal/modules/esm/translators.js:199:29)
    at ModuleJob.run (internal/modules/esm/module_job.js:170:25)
    at async Loader.import (internal/modules/esm/loader.js:178:24)
    at async __instantiateModule__ (file://some_folder/.nuxt/dist/server/server.mjs:2319:3)

Let me know if there is any more information I can give you.

Link to reproduction

https://codesandbox.io/s/nuxt3-vanilla-extract-cpfce

System Info

Output of npx envinfo --system --npmPackages @vanilla-extract/css,@vanilla-extract/webpack-plugin,@vanilla-extract/esbuild-plugin,@vanilla-extract/vite-plugin,@vanilla-extract/sprinkles,webpack,esbuild,vite --binaries --browsers:

  System:
    OS: Linux 5.11 Ubuntu 21.04 (Hirsute Hippo)
    CPU: (6) x64 Intel(R) Core(TM) i5-8600K CPU @ 3.60GHz
    Memory: 3.24 GB / 15.57 GB
    Container: Yes
    Shell: 5.1.4 - /bin/bash
  Binaries:
    Node: 14.17.6 - /tmp/fnm_multishells/1605_1634115304080/bin/node
    Yarn: 1.22.11 - /tmp/fnm_multishells/1605_1634115304080/bin/yarn
    npm: 6.14.15 - /tmp/fnm_multishells/1605_1634115304080/bin/npm
  Browsers:
    Chrome: 94.0.4606.81
    Firefox: 93.0
  npmPackages:
    @vanilla-extract/css: ^1.6.2 => 1.6.2
    @vanilla-extract/vite-plugin: ^2.1.3 => 2.1.3
@mattcompiles
Copy link
Contributor

This looks related to the following nuxt issue. nuxt/nuxt#11970

@tkofh
Copy link

tkofh commented Oct 27, 2021

A workaround for this is transpiling @vanilla-extract, outdent, & @emotion like this:

import { vanillaExtractPlugin } from '@vanilla-extract/vite-plugin'
import { defineNuxtConfig } from 'nuxt3'

export default defineNuxtConfig({
  vite: {
    plugins: [
      vanillaExtractPlugin(),
    ]
  },
  build: {
    transpile: ['@vanilla-extract', 'outdent', '@emotion']
  }
})

Repo (part of my ssr issue, nuxt/nuxt#11827)

@leithonenglish
Copy link

I have a similar issue when I try to integrate vanilla extract. I get a slightly different error even when I try to add the plugin with what's above ☝🏼.
Error: couldn't find parent package.json with a name field. Anyone has any fix for this as yet?

@tkofh
Copy link

tkofh commented May 3, 2022

I have a similar issue when I try to integrate vanilla extract. I get a slightly different error even when I try to add the plugin with what's above ☝🏼. Error: couldn't find parent package.json with a name field. Anyone has any fix for this as yet?

@leithonenglish This error can be resolved by adding "name": "my-app" (or whatever name you choose) to your project's package.json. Vanilla Extract looks for the package name to prepend to the virtual modules it creates.

@leithonenglish
Copy link

That works perfectly but now when I try to import any of the styles, for example,
app.css.ts

import { style } from "@vanilla-extract/css";

export const wrapperStyle = style({
  background: `red`,
});

app.vue

<script lang="ts" setup>
import { wrapperStyle } from "./app.css";
</script>
<template>
  <div :class="wrapperStyle">Hey there</div>
</template>

I get the following warning (node:43589) Warning: To load an ES module, set "type": "module" in the package.json or use the .mjs extension. and the server never loads the page.
I tried getting info from here https://v3.nuxtjs.org/guide/going-further/esm/ but still not sure what I am missing

@leithonenglish
Copy link

No updates on this?

@ljani
Copy link

ljani commented Dec 20, 2022

I get the following warning (node:43589) Warning: To load an ES module, set "type": "module" in the package.json or use the .mjs extension. and the server never loads the page.

I think I'm facing the same issue with SvelteKit. Someone commented that Node does not like .esm.js and it should be eg. vanilla-extract-css.mjs.

noExternal used to work, but that does not seem to be the case anymore.

@ljani
Copy link

ljani commented Dec 21, 2022

Renaming the file to end with .mjs seems to get rid of the errors. Here's another one suggesting fixing the extension.

@ljani
Copy link

ljani commented Dec 21, 2022

Okay, my error seems to be fixed by updating to Vite 4.0.3 released 5 hours ago, heh. I guess it was this one.

Anyway, .mjs should be used over .esm.js, or .cjs over .cjs.js, and css-what should be upgraded to v6 so it is ESM, not CJS.

@graup
Copy link
Collaborator

graup commented May 21, 2023

I just tested this and don't seem to get any errors. If nobody has anything to add here, I'd close this issue.

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

6 participants