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

Compilation error with Webpack. (Can't resolve '../package') #2656

Closed
Rojoss opened this issue Jul 13, 2018 · 2 comments
Closed

Compilation error with Webpack. (Can't resolve '../package') #2656

Rojoss opened this issue Jul 13, 2018 · 2 comments

Comments

@Rojoss
Copy link

Rojoss commented Jul 13, 2018

Please describe the problem you are having in as much detail as possible:
Compilation error with Webpack.
When using the bot normally it works totally fine but when compiling with Webpack (I use Typescript) I get the following error.

ERROR in ./node_modules/discord.js/src/index.js
Module not found: Error: Can't resolve '../package' in 'C:\workspace\EmojiQuiz\node_modules\discord.js\src'
 @ ./node_modules/discord.js/src/index.js 21:11-32
 @ ./src/DiscordServer.ts
 @ ./src/Main.ts

Include a reproducible code sample here, if possible:
If needed I can set up a blank project with the same webpack config and basic setup tonight or tomorrow.
But here is my Webpack config.
https://gist.github.com/Rojoss/38306aac843a4ddbcae5e1c641bbe268
./node_modules/.bin/webpack --mode=development --progress --colors

Regarding the code I just copied the example which obviously works when I just run the js file with node.

const Discord = require('discord.js');
const client = new Discord.Client();

client.on('ready', () => {
  console.log(`Logged in as ${client.user.tag}!`);
});

client.on('message', msg => {
  if (msg.content === 'ping') {
    msg.reply('Pong!');
  }
});

client.login('...');

Further details:

  • discord.js version: 11.3.2
  • node.js version: 8.11.3
  • Operating system: Windows 10 x64
  • Priority this issue should have: normal
@Rojoss
Copy link
Author

Rojoss commented Jul 13, 2018

Managed to fix it by fiddling around a bit with my Webpack config.
Turned out I had to add json to resolve array.
So if anyone else is ever having this issue this is how you can fix it.

module.exports = {
    // ...

    resolve: {
        modules: ['src', 'node_modules'],
        extensions: ['.tsx', '.ts', '.js', '.json']
    }

    // ...
};

@dreamerkumar
Copy link

Thanks @Rojoss I had the below error while trying to use the express-device package. It has code to require the package.json file to pull the version from it. And was getting the below error. Adding .json to the list of extensions fixed the problem.

require('../package').version Module not found: Error: Can't resolve '../package'

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 26, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants