【发布时间】:2021-11-30 06:56:17
【问题描述】:
我正在我的 Windows 计算机以及我的 Macbook 上处理一个项目。我有一个函数,可以像这样注册全局某些目录中定义的组件:
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' });
当我运行 npm run watch 或 dev 或 prod 时,它会编译代码并成功地在我的 Windows 机器上显示网站。但是当我在我的 Macbook 上执行此操作时,它会引发以下错误:
无法解析“/Users/bas/Sites/trainfit/resources/js”中的“./components”
这有什么理由可以在 Windows 机器上运行,但不能在运行 MacOS 的机器上运行?
关于我的项目的更多信息:
- 使用 Vue 和 Inertiajs 制作
- 从 Visual Studio Code 运行此代码
【问题讨论】:
-
您的代码看起来不完整。
require和requireComponent对象是什么?在 Windows/MacOS 中运行是什么意思?您是在 Node、浏览器中运行,还是在什么地方运行?你错过了一些额外的标签吗? -
Windows和MacOS的文件夹结构一样吗?
-
@CascadiaJS 我的项目的文件夹结构是一样的。但是机器上项目的路径是不同的。 MacOS
/var/www/Sites/projectname和 WindowsD://laragon/www/projectname。 -
无法解析错误表示,
file not found错误
标签: javascript windows macos