discordjs / builders

A collection of builders that you can use when creating your bot.
Apache License 2.0
97 stars 37 forks source link

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

Closed KhafraDev closed 2 years ago

KhafraDev commented 2 years ago

Issue description

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

  1. Install @discordjs/builders@0.8.1
  2. Set up an esm project
  3. Try the sample code

This issue did not occur on v0.7.x. edit: https://github.com/sindresorhus/ow/issues/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 commented 2 years ago

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 commented 2 years ago

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

"resolutions": {
  "ow": "0.27.0"
}
Gamer025 commented 2 years ago

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 (https://github.com/sindresorhus/ow/issues/215) also said they have this problem with 0.27.0 image I also tried creating a completely new Node project and installed only ow@0.27.0 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 commented 2 years ago

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

NateFlynn-Silktide commented 2 years ago

Is there any solution for this at the moment? I'm getting the same error on a fresh build with @discord/builders@0.8.2 and ow@0.27.0.

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

KhafraDev commented 2 years ago

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

VIKTORVAV99 commented 2 years ago

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 commented 2 years ago

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

The author of the first PR attempting to fix this issue (https://github.com/discordjs/builders/pull/55) used a closing keyword which is triggered on merge into the main branch.

VIKTORVAV99 commented 2 years ago

Ah that makes sense, thanks for reopening it.

ramennbowls commented 2 years ago

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 commented 2 years ago

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 commented 2 years ago

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