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

TypeError: util2.strToChars is not a function in Typia 6.10.0 with Angular 18 and TypeScript 5.5.4 #1277

Closed
Karbashevskyi opened this issue Sep 14, 2024 · 8 comments
Assignees
Labels
bug Something isn't working enhancement New feature or request

Comments

@Karbashevskyi
Copy link

Karbashevskyi commented Sep 14, 2024

Here's the updated bug report with the correct Typia version:


Bug Report

Note that the bug you're reporting may have already been registered in the issues by another user. The bug may also have been fixed in the @next version. For that reason, I recommend checking the old issues and reproducing your code with the @next version before publishing the bug reporting issue.

npm install --save-dev typia@next

When the same error occurs even in the @next version, please fill in the template below:


📝 Summary

Encountering TypeError: util2.strToChars is not a function when using Typia with Angular 18, TypeScript 5.5.4, and Node.js 20.11.1.

  • Typia Version: 6.10.0 (Latest)
  • Expected behavior: Typia should run without errors in a standard Angular project.
  • Actual behavior: Runtime error occurs, indicating util2.strToChars is not a function.

I encountered this issue during runtime after setting up Typia with Angular and TypeScript. The error suggests that a function (strToChars) is missing or unavailable in a utility module that Typia relies on.


⏯ Playground Link

[No playground link available as the issue is specific to an Angular setup.]


💻 Code Occurring the Bug

import {Component} from '@angular/core';
import {Enum} from "@src/module/utility/domain";
import typia, {tags} from "typia";
import {CustomerTypeEnum} from "@customer/domain/enum/customer-type.enum";
import {IBaseEntity} from "@utility/domain/interface";

export interface IBaseEntity<OBJECT_TYPE extends string> {
    // Added by the system
    _id: string & tags.Pattern<'^(?=[a-f\\d]{24}$)(\\d+[a-f]|[a-f]+\\d)'>;
    createdAt: string & tags.Format<'date-time'>;
    updatedAt: string & tags.Format<'date-time'>;
    object: OBJECT_TYPE;
}

export type RIBaseEntity<OBJECT_TYPE extends string> = Required<IBaseEntity<OBJECT_TYPE>>;

/**
 * Declare interface by business logic, if you need case when each property is optional, use Partial<ICustomer>
 */
export interface ICustomer extends IBaseEntity<'CustomerDto'> {
    firstName: string & tags.MaxLength<50> | null;
    lastName: string & tags.MaxLength<50> | null;
    phone: string | null;
    email: string & tags.Format<"email"> | null;
    note: string | null;
    customerType: CustomerTypeEnum & tags.Default<CustomerTypeEnum.new>;
    active: Enum.ActiveEnum & tags.Default<Enum.ActiveEnum.YES>;
}

export const isCustomer = typia.createIs<ICustomer>();
export const validCustomer = typia.createValidate<ICustomer>();
export const randomCustomer = typia.createRandom<ICustomer>();

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css']
})
export class AppComponent {
  title = 'typia-angular-integration';

  constructor() {
    console.log(randomCustomer())
  }
}

Error Trace:

TypeError: util2.strToChars is not a function
    at [file]:[line number]

💡 Additional Information

  • Environment Details:
    • Angular Version: 18.x (Latest)
    • TypeScript Version: 5.5.4
    • Node.js Version: 20.11.1
    • Operating System: MacOS

I’ve ensured that all dependencies are up to date and have also attempted reinstalling node modules using rm -rf node_modules && npm install. Despite this, the issue persists.

This error seems to stem from a missing or deprecated function in one of Typia's dependencies. I was unable to locate strToChars in the utility modules involved.

Any guidance on resolving this would be appreciated!


Let me know if any further adjustments are needed!

@samchon samchon self-assigned this Sep 19, 2024
@samchon samchon added bug Something isn't working enhancement New feature or request labels Sep 19, 2024
@samchon
Copy link
Owner

samchon commented Sep 19, 2024

@ryoppippi Tried by myself, but failed to escape this problem.

I disabled preserveModules option for a while, just to fix this bug.

If you know how to escape it, please help me.

samchon added a commit that referenced this issue Sep 19, 2024
Fix #1277: disable `preserveModules` of `rollup` configuration.
@github-project-automation github-project-automation bot moved this from To do to Done in Typia v6 Update Sep 19, 2024
@ryoppippi
Copy link
Contributor

@samchon I cannot find the strToChars
Where is the function implemented.

@ryoppippi
Copy link
Contributor

@Karbashevskyi If you create a reproduction repository, it makes life easier

@samchon
Copy link
Owner

samchon commented Sep 19, 2024

@ryoppippi Here it is.

Such _virtual directory exported empty object is used in the ret library.

Also, you can test it with previous typia version.

image

@ryoppippi
Copy link
Contributor

ryoppippi commented Sep 19, 2024

Ok, let me check
This comes with ret

@ryoppippi
Copy link
Contributor

Hmm, in my local build, it is not missing

@ryoppippi
Copy link
Contributor

Oh, okay. I got it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working enhancement New feature or request
Projects
No open projects
Status: Done
Development

No branches or pull requests

3 participants