xiCO2k / laravel-vue-i18n

Allows to connect your `Laravel` Framework translation files with `Vue`.
MIT License
598 stars 49 forks source link

Cannot find module './en.json' #79

Closed yoeriboven closed 1 year ago

yoeriboven commented 1 year ago

Hi Francisco,

I can't get the package to work with PHP files.

I followed these steps (no SSR): https://github.com/xiCO2k/laravel-vue-i18n#with-webpack--laravel-mix

The console says this: Unhandled Promise Rejection: Error: Cannot find module './en.json'.

The file /public/js/lang_php_en_json.js exists.

Also is resolving as instructed in app.js correct? The file ../../lang/${lang}.json does not exist. In ../../lang/en/ are my PHP translation files. No json file.

Any idea what to do?

yoeriboven commented 1 year ago

Right after posting this it suddenly worked.

The same error message persists though.

It's thrown at the top of my app.js

/******/ (() => { // webpackBootstrap
/******/    var __webpack_modules__ = ({

/***/ "./lang lazy recursive ^\\.\\/.*\\.json$":
/*!****************************************************!*\
  !*** ./lang/ lazy ^\.\/.*\.json$ namespace object ***!
  \****************************************************/
/***/ ((module, __unused_webpack_exports, __webpack_require__) => {

var map = {
    "./php_en.json": [
        "./lang/php_en.json",
        "lang_php_en_json"
    ],
    "./php_nl.json": [
        "./lang/php_nl.json",
        "lang_php_nl_json"
    ]
};
function webpackAsyncContext(req) {
    if(!__webpack_require__.o(map, req)) {
        return Promise.resolve().then(() => {
            var e = new Error("Cannot find module '" + req + "'");
            e.code = 'MODULE_NOT_FOUND';
            throw e;
        });
    }

    var ids = map[req], id = ids[0];
    return __webpack_require__.e(ids[1]).then(() => {
        return __webpack_require__.t(id, 3 | 16);
    });
}
webpackAsyncContext.keys = () => (Object.keys(map));
webpackAsyncContext.id = "./lang lazy recursive ^\\.\\/.*\\.json$";
module.exports = webpackAsyncContext;
xiCO2k commented 1 year ago

If possible can you provide your app.js file, to try to debug here?

Thanks.

yoeriboven commented 1 year ago
import {createApp, h} from 'vue';
import {createInertiaApp, Link} from '@inertiajs/inertia-vue3';
import {InertiaProgress} from '@inertiajs/progress';
import {i18nVue} from 'laravel-vue-i18n'
import {ZiggyVue} from '../../vendor/tightenco/ziggy/dist/vue.m';
import {modal} from "momentum-modal"

const appName = window.document.getElementsByTagName('title')[0]?.innerText || 'Appname';

createInertiaApp({
    title: (title) => `${title} - ${appName}`,
    resolve: (name) => require(`./Pages/${name}.vue`),
    setup({ el, app, props, plugin }) {
        return createApp({ render: () => h(app, props) })
            .use(plugin)
            .use(modal, {
                resolve: (name) => require(`./Pages/${name}.vue`),
            })
            .use(ZiggyVue, Ziggy)
            .use(i18nVue, {
                resolve: lang => import(`../../lang/${lang}.json`),
            })
            .component('Link', Link)
            .mount(el);
    },
});

InertiaProgress.init({ color: '#4B5563' });
Alex1993St commented 1 year ago

I have the same problem: Uncaught (in promise) Error: Cannot find module './en.json'

// app.js

import './bootstrap'; import { createApp } from 'vue' import { i18nVue } from 'laravel-vue-i18n' import DataList from './components/Table.vue'

const app = createApp({}) app.component('data-list', DataList)

app.use(i18nVue, { resolve: lang => import(../../lang/${lang}.json), })

app.mount('#app')

// webpack.mix.js const mix = require('laravel-mix'); require('laravel-vue-i18n/mix');

mix.js('resources/js/app.js', 'public/js') .vue() .i18n() .postCss('resources/css/app.css', 'public/css', [ // ]);

xiCO2k commented 1 year ago

Hey @yoeriboven its possible for you to create a public repo, with that issue?

Trying to replicate without luck.

Thanks

fheider commented 1 year ago

closed? this bug is still there

yoeriboven commented 1 year ago

@fheider Hi, if you still got this issue please do what Francisco asked in the comment above. I don't work on a project that has this issue anymore.

fheider commented 1 year ago

its an error in the loader file, cause there you name the file

line 58 return { name: 'php_${folder}.json', translations }

if i change this, all is fine. i solved it for me with an empty en.json file cause i dont need the php translations.

xiCO2k commented 1 year ago

Can you create a repo for me with that exact problem?

Thanks.