Estoy trabajando en un proyecto en mi computadora con Windows también en mi Macbook. Obtuve una función que registra componentes definidos en ciertos directorios globalmente como este:
require('./bootstrap'); import { createApp, h } from 'vue'; import { createInertiaApp } from '@inertiajs/inertia-vue3'; import { InertiaProgress } from '@inertiajs/progress'; /** * Third-party imports. */ import upperFirst from 'lodash/upperFirst'; import camelCase from 'lodash/camelCase'; const appName = window.document.getElementsByTagName('title')[0]?.innerText || 'Laravel'; /** * Register components from the ./components and ./components/core * directories. This way these components don't have to be imported * manually every time. * * The core components are the core of other components and contains * alerts, notifications, input fields etc. * * Base components are bigger components made upon the core components * and contain a combination of one or more of the core components. These * are usually components that contain a lot of code and have to be re-used * across the whole application. * * @param {Vue instance} app */ function registerGlobalComponents (app) { const requireComponent = require.context( './components' || './components/core' || './components/base', true, /\.vue$/ ); for (const file of requireComponent.keys()) { const componentConfig = requireComponent(file); const name = file .replace(/index.js/, '') .replace(/^\.\//, '') .replace(/\.\w+$/, ''); const componentName = upperFirst(camelCase(name)); app.component(componentName, componentConfig.default); } } createInertiaApp({ title: (title) => `${title} - ${appName}`, resolve: (name) => require(`./Pages/${name}.vue`), setup({ el, app, props, plugin }) { const inertiaApp = createApp({ render: () => h(app, props) }); inertiaApp.use(plugin); inertiaApp.mixin({ methods: { route } }) registerGlobalComponents(inertiaApp); inertiaApp.mount(el); }, }); InertiaProgress.init({ color: '#4B5563' }); Cuando ejecuto npm run watch o dev o prod , compila el código y me muestra correctamente el sitio web en mi máquina con Windows. Pero cuando hago esto en mi Macbook, arroja el siguiente error:
No se puede resolver './components' en '/Users/bas/Sites/trainfit/resources/js'
¿Hay alguna razón por la que esto funcione en una máquina con Windows pero no en una máquina que se ejecuta en MacOS?
Más información sobre mi proyecto:
Como se explica en los documentos , comienza creando un archivo jsconfig.json en su raíz con estos caracteres y símbolos:
{ "compilerOptions": { "baseUrl": "src" }, "include": ["src"] }Puede encontrar ejemplos y referencias aquí: - aquí