Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
1 task done
akyrey opened this issue May 27, 2022 · 5 comments
Closed
1 task done

Comments

@akyrey
Copy link

akyrey commented May 27, 2022

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 akyrey changed the title Bug: Bug: Cannot read properties of undefined (reading 'split') from translationPath May 27, 2022
@shaharkazaz
Copy link
Collaborator

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

@akyrey
Copy link
Author

akyrey commented Jul 27, 2022

I'll try to create a reproduction!

@shaharkazaz
Copy link
Collaborator

@akyrey I managed to create one 👍

@shaharkazaz
Copy link
Collaborator

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

@akyrey
Copy link
Author

akyrey commented Aug 24, 2022

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants