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

fix: add suggestion how to fix importing CJS module #21764

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

bartlomieju
Copy link
Member

Screenshot 2024-01-02 at 22 16 22

Similar mechanism can be used to fix #21712

cli/main.rs Outdated
if e.name == Some("ReferenceError".to_string()) {
if let Some(msg) = &e.message {
if msg.contains("module is not defined") {
error_string = format!("{}\n\n {} Deno doesn't support CommonJS modules, change problematic module into an ES module.", error_string, colors::cyan("hint:"))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe something like

Deno doesn't support CommonJS in user code, that is, outside of npm modules. Consider converting the above file to ES module syntax.

Not so sure about hard coding colors like this. Maybe colors::bold instead?

@littledivy
Copy link
Member

littledivy commented Jan 3, 2024

Really like the idea of providing suggestions.

Here's a little more real-worldy next config: https://github.com/timlrx/tailwind-nextjs-starter-blog/blob/main/next.config.js

Ideally Deno could provide suggestions for migration:

| const { withContentlayer } = require('next-contentlayer')
                               ^^^^^^^
Deno doesn't support CommonJS in user code, that is, outside of npm modules.

hint: use `import { withContentLayer } from "next-contentlayer"`;

| const withBundleAnalyzer = require('@next/bundle-analyzer')({
                             ^^^^^^^

Deno doesn't support CommonJS in user code, that is, outside of npm modules.

hint: use:
          import $ from "@next/bundle-analyzer";
          const withBundleAnalyzer = $({
            enabled: process.env.ANALYZE === 'true',
          });

@scarf005
Copy link
Contributor

Ideally Deno could provide suggestions for migration:

being able to have a CLI option to autofix given hint would really be helpful.

@bartlomieju bartlomieju marked this pull request as ready for review May 21, 2024 23:30
@bartlomieju bartlomieju modified the milestones: 1.44, 1.45 May 21, 2024
@dsherret dsherret modified the milestones: 1.45, 1.46 Jul 10, 2024
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

Successfully merging this pull request may close these issues.

Better error message when missing --unstable
5 participants