jsverse/transloco-keys-manager

Bug: Cannot read properties of undefined (reading 'split') from translationPath

akyrey opened this issue · 5 comments

Is there an existing issue for this?

  • I have searched the existing issues

Is this a regression?

Yes

Current behavior

After uploading to transloco version 4.0.0, I was no longer able to use this library, getting the following error:

⠋ Checking for missing keys ✨/folder/node_modules/@ngneat/transloco-keys-manager/utils/path.utils.js:1
"use strict";var __createBinding=this&&this.__createBinding||(Object.create?function(t,e,o,a){void 0===a&&(a=o),Object.defineProperty(t,a,{enumerable:!0,get:function(){return e[o]}})}:function(t,e,o,a){void 0===a&&(a=o),t[a]=e[o]}),__setModuleDefault=this&&this.__setModuleDefault||(Object.create?function(t,e){Object.defineProperty(t,"default",{enumerable:!0,value:e})}:function(t,e){t.default=e}),__importStar=this&&this.__importStar||function(t){if(t&&t.__esModule)return t;var e={};if(null!=t)for(var o in t)"default"!==o&&Object.prototype.hasOwnProperty.call(t,o)&&__createBinding(e,t,o);return __setModuleDefault(e,t),e};Object.defineProperty(exports,"__esModule",{value:!0}),exports.buildScopeFilePaths=exports.resolveConfigPaths=exports.getScopeAndLangFromPath=exports.buildPath=exports.pathUnixFormat=void 0;const path_1=__importStar(require("path")),config_1=require("../config"),validators_utils_1=require("./validators.utils");function pathUnixFormat(t){return t.split(path_1.sep).join("/")}function buildPath(t){return Object.keys(t).reduce(((e,o)=>{const a=(0,validators_utils_1.isObject)(t[o])?buildPath(t[o]).map((t=>`${o}.${t}`)):[o];return e.push(...a),e}),[])}function getScopeAndLangFromPath({filePath:t,translationsPath:e,fileFormat:o}){t=pathUnixFormat(t),!1===(e=pathUnixFormat(e)).endsWith("/")&&(e=`${e}/`);const[a,r]=t.split(e),i=r.split("/"),n=t=>t.replace(`.${o}`,"");let s,u;return i.length>1?(u=n(i.pop()),s=i.join("/")):u=n(i[0]),{scope:s,lang:u}}function resolveConfigPaths(t,e){const o=t=>path_1.default.resolve(process.cwd(),e,t);t.input=t.input.map(o),["output","translationsPath"].forEach((e=>{t[e]=o(t[e])}))}function buildScopeFilePaths({aliasToScope:t,output:e,langs:o,fileFormat:a}){const{scopePathMap:r={}}=(0,config_1.getConfig)();return Object.values(t).reduce(((t,i)=>(o.forEach((o=>{let n=r[i]?r[i]:`${e}/${i}`;t.push({path:`${n}/${o}.${a}`,scope:i})})),t)),[])}exports.pathUnixFormat=pathUnixFormat,exports.buildPath=buildPath,exports.getScopeAndLangFromPath=getScopeAndLangFromPath,exports.resolveConfigPaths=resolveConfigPaths,exports.buildScopeFilePaths=buildScopeFilePaths;


TypeError: Cannot read properties of undefined (reading 'split')
    at getScopeAndLangFromPath (/folder/node_modules/@ngneat/transloco-keys-manager/utils/path.utils.js:1:1359)
    at compareKeysToFiles (/folder/node_modules/@ngneat/transloco-keys-manager/keys-detective/compare-keys-to-files.js:1:2050)
    at findMissingKeys (/folder/node_modules/@ngneat/transloco-keys-manager/keys-detective/index.js:1:1039)
    at Object.<anonymous> (/folder/node_modules/@ngneat/transloco-keys-manager/index.js:2:1082)
    at Module._compile (node:internal/modules/cjs/loader:1105:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1159:10)
    at Module.load (node:internal/modules/cjs/loader:981:32)
    at Function.Module._load (node:internal/modules/cjs/loader:822:12)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:77:12)
    at node:internal/main/run_main_module:17:47

Opening a pull request to handle the problem

Expected behavior

Shouldn't return an error and complete like it previously did

Please provide a link to a minimal reproduction of the bug

Don't have a link

Transloco Config

module.exports = {
  rootTranslationsPath: 'assets/i18n',
  langs: ['it', 'en'],
  keysManager: {},
  scopePathMap: {
    scope1: 'src/app/modules/scope1/i18n',
    scope2: 'src/app/modules/scope2/i18n'
  },
};

Debug Logs

No relevant info

Please provide the environment you discovered this bug in

Transloco: 4.0.0
Transloco Keys Manager: 3.4.1
Angular: 13.2.2
Node: 16.15.0
Package Manager: npm 8.5.5
OS: Mac OSX

Additional context

No response

I would like to make a pull request for this bug

Yes 🚀

@akyrey How is this related to transloco v4? can you please create a small reproduction?

I'll try to create a reproduction!

@akyrey I managed to create one 👍

@akyrey Can you please verify that 3.4.2 solves your issue?

Sorry for the late response! Yeah, it's resolved! I tried it on different projects and everything is working fine! Thank you very much!