Skip to content
This repository has been archived by the owner on Jan 8, 2022. It is now read-only.

ESM TypeError: Cannot read properties of undefined (reading 'minLength') #54

Closed
KhafraDev opened this issue Oct 30, 2021 · 12 comments · Fixed by #55
Closed

ESM TypeError: Cannot read properties of undefined (reading 'minLength') #54

KhafraDev opened this issue Oct 30, 2021 · 12 comments · Fixed by #55
Labels
bug Something isn't working need repro

Comments

@KhafraDev
Copy link
Contributor

KhafraDev commented Oct 30, 2021

Issue description

This issue is caused by ow, as the code below shows.

  1. Install @discordjs/[email protected]
  2. Set up an esm project
  3. Try the sample code

This issue did not occur on v0.7.x.
edit: sindresorhus/ow#215

Code sample

import { SlashCommandBuilder } from '@discordjs/builders';
new SlashCommandBuilder();

// or

import ow from 'ow';
ow.string.minLength(1); // ow.string is undefined

@discordjs/builders version

0.8.1

Node.js version

16.13.0

Operating system

Windows

Priority this issue should have

High (immediate attention needed)

@DuckingElias
Copy link

DuckingElias commented Oct 30, 2021

Temporary solution:

  1. Type npm shrinkwrap. This deletes your package-lock.json and creates an npm-shrinkwrap.json
  2. Inside the npm-shrinkwrap.json, search for node_modules/@discordjs/builders
  3. Under dependencies of node_modules/@discordjs/builders, change the version of ow to ^0.27.0
  4. Delete your node_modules and type npm install

@favna
Copy link
Contributor

favna commented Oct 30, 2021

Or temporary solution for yarn users add to your package.json

"resolutions": {
  "ow": "0.27.0"
}

@Gamer025
Copy link

Did the linked PR actually fix this issue?
I also had this problem yesterday and updated to 0.8.2 today, but im still getting the same error when trying to import @discordjs/builders.
Already reset my modules folder to make sure its using ow 0.27.0 and builder 0.8.2
Someone in the linked ow issue (sindresorhus/ow#215) also said they have this problem with 0.27.0
image
I also tried creating a completely new Node project and installed only [email protected] and tried to run a mjs file only containing:

import ow from 'ow';
ow.string.minLength(1);

Still resulted in TypeError: Cannot read properties of undefined (reading 'minLength')
image

@KhafraDev
Copy link
Contributor Author

no it didn't, but it took some time for a real fix @Gamer025 sorry about that

@NateFlynn-Silktide
Copy link

Is there any solution for this at the moment? I'm getting the same error on a fresh build with @discord/[email protected] and [email protected].

Got plenty of other bits to be working on in the meantime if the fix for this is still a way off 🙂

@KhafraDev
Copy link
Contributor Author

there is a pr to fix this linked above, in the meantime you can force install an older builders version with npm i @discordjs/[email protected]

@VIKTORVAV99
Copy link

Why was this issue closed when the issue itself hasn't been resolved?

I was about to create a new issue for it before I looked at pull requests where #56 linked here.

@almostSouji
Copy link
Member

almostSouji commented Nov 9, 2021

Why was this issue closed when the issue itself hasn't been resolved?

The author of the first PR attempting to fix this issue (#55) used a closing keyword which is triggered on merge into the main branch.

@almostSouji almostSouji reopened this Nov 9, 2021
@VIKTORVAV99
Copy link

Ah that makes sense, thanks for reopening it.

@ramennbowls
Copy link

If this helps at all, even after having 'ow' downgraded to ^0.27.0, the error still occurs for me but only when importing it using ES6.

import { SlashCommandBuilder } from '@discordjs/builders'

When using 'require', the error doesn't appear.

const { SlashCommandBuilder } = require('@discordjs/builders')

@favna
Copy link
Contributor

favna commented Nov 27, 2021

If this helps at all, even after having 'ow' downgraded to ^0.27.0, the error still occurs for me but only when importing it using ES6.

import { SlashCommandBuilder } from '@discordjs/builders'

When using 'require', the error doesn't appear.

const { SlashCommandBuilder } = require('@discordjs/builders')

There is no require in ESM. Anyway there are PRs #56 and #58 and whichever will end up being merged will mean ow is gone and this problem is resolved.

@ze
Copy link

ze commented Dec 6, 2021

#58 Fixed the bug for me! Now the discordjs package needs to be updated to use 0.9.0 instead of 0.8.2!

@kyranet kyranet closed this as completed Dec 6, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working need repro
Projects
None yet
Development

Successfully merging a pull request may close this issue.

10 participants