Skip to content
This repository has been archived by the owner on Jan 4, 2023. It is now read-only.

require is not defined when using nuxtjs/composition-api #134

Closed
kylemod opened this issue May 8, 2021 · 7 comments
Closed

require is not defined when using nuxtjs/composition-api #134

kylemod opened this issue May 8, 2021 · 7 comments
Labels
bug Something isn't working

Comments

@kylemod
Copy link

kylemod commented May 8, 2021

Versions

nuxt-vite: 0.0.37
nuxt: 2.15.4

Reproduction

A fresh install of nuxt app and nuxtjs/composition-api

Description

It just says require is not defined at http://localhost:3000/@fs/my/storage/path/nuxt-vite/node_modules/@nuxtjs/composition-api/dist/register.js?v=c9e46a53:3:13 in my console

And when i use a hook like onMounted, my terminal printed ERROR [Vue warn]: onMounted is called when there is no active component instance to be associated with. Lifecycle injection APIs can only be used during execution of setup().

@kylemod kylemod added the bug Something isn't working label May 8, 2021
@yaiks
Copy link

yaiks commented May 9, 2021

Hey @kylemod, I've also run into this issue and I guess this is a bug on the @nuxt/composition-api library. I opened an issue there with my findings, feel free to jump in and talk about your experience.

danielroe added a commit to nuxt-community/composition-api that referenced this issue May 17, 2021
* addresses issue with .mjs format (nuxt + jest)
* uses `require.resolve` to locate templates
* compile composables into single file
* reverts 16e21eb (#470)
* retains auto-registration for testing (in cjs export - if `process.env.NODE_ENV === 'test'`)

closes #476, closes #479 (by implementing), closes nuxt/vite#134, closes nuxt/vite#123
danielroe added a commit to nuxt-community/composition-api that referenced this issue May 21, 2021
* addresses issue with .mjs format (nuxt + jest)
* compile composables into single file
* registers composition API using webpack entrypoint (or, for vite, by overriding `./middleware.js` import)
* retains auto-registration for testing (in cjs export - if `process.env.NODE_ENV === 'test'`)

closes #476, closes #479 (by implementing)

Also should cover nuxt/vite#134 and nuxt/vite#123.
@kylemod
Copy link
Author

kylemod commented May 22, 2021

Closing issue. See rework composition api registration

@kylemod kylemod closed this as completed May 22, 2021
@manoj-mukherjee-maersk
Copy link

img if using require giving same error <img :src="require(~/assets/icons/${menuItem.iconName}.svg)" />
any solution?

@justice47
Copy link

justice47 commented Sep 16, 2021

img if using require giving same error <img :src="require(~/assets/icons/${menuItem.iconName}.svg)" />
any solution?

Did you found a solution?
I'm running into this too

@cyanerd
Copy link

cyanerd commented Dec 23, 2021

img if using require giving same error <img :src="require(~/assets/icons/${menuItem.iconName}.svg)" /> any solution?

same problem. did u find any solution?

@kayoderock
Copy link

@cyanerd you are most likely using Vite for your packing.

@kayoderock
Copy link

In template:
<img class="bp-icon" :src="imgUrl" alt="">

In the script:
mounted () { this.imgUrl = new URL(../assets/img/${this.icon}.svg, import.meta.url) }

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

6 participants