nuxt
nuxt copied to clipboard
extendRoutes fails to import script at runtime with ReferenceError
Versions
- nuxt: v2.15.8
- node: v16.14.2
Reproduction
Additional Details
nuxt.config.js
import extendRoutes from './scripts/extendRoutes';
const config = {
router: {
base: process.env.BASE_URL,
extendRoutes: extendRoutes,
},
// Global page headers: https://go.nuxtjs.dev/config-head
head: {
title: 'import-bug',
htmlAttrs: {
lang: 'en'
},
meta: [],
link: []
},
// Auto import components: https://go.nuxtjs.dev/config-components
components: true,
// Modules: https://go.nuxtjs.dev/config-modules
modules: [
// https://go.nuxtjs.dev/axios
'@nuxtjs/axios'
],
}
export default config;
extendRoutes.js
import editRoute from './editRoute';
export default function (routes) {
routes.push(
{
path: '/from',
redirect: (route) => {
editRoute('');
return '/to';
},
}
);
}
editRoute.js
export default (path) => {
return path;
};
Steps to reproduce
I'm importing my extendRoutes
to push new routes to the nuxt router.
This extendsRoutes.js
file imports another script. Run nuxt
.
I've attached a sample file: Reproduction.zip
Just run yarn
, and then nuxt
What is Expected?
Scripts can be imported without error, or I should see a reasonable error when running nuxt
What is actually happening?
When I load the site and extendRoutes
is evaluated, I get a ReferenceError that the module I'm importing is not defined.