web-infra-dev / rspack

The fast Rust-based web bundler with webpack-compatible API 🦀️
https://rspack.dev
MIT License
9.34k stars 543 forks source link

Provide more accurate error prompts when the import path does not exist #4769

Closed Ninglo closed 8 months ago

Ninglo commented 10 months ago

When I try to compile a project with a non-existent path in import, rspack will display an error message like this:

error[internal]: Resolve error
  ┌─ src/main/index.ts:1:1
  │  
1 │ ╭ import './non-existent/path'
2 │ │ 
  │ ╰^ Failed to resolve ./non-existent/path in typescript|<my_entry_path>

This error is emphasized on typescript, but typescript has absolutely nothing to do with the cause of this problem. Especially in a non-code resource, such an error message will make people think that it is a loader problem rather than a path problem. For example:

error[internal]: Resolve error
  ┌─ src/main/index.ts:1:1
  │  
1 │ ╭ import './non-existent/path/foo.node'
2 │ │ 
  │ ╰^ Failed to resolve ./non-existent/foo.node in typescript|<my_entry_path>
Ninglo commented 10 months ago
System:
    OS: macOS 13.6.1 (22G313)
    CPU: 2.6 GHz 6-Core Intel Core i7
    Memory: 32 GB 2667 MHz DDR4
  npmPackages:
    @rsbuild/cli: 0.3.14
Ninglo commented 10 months ago

Source code:

// src/main/index.ts
import './non-existent/path/foo.node'
// rspack.config.js
const path = require('path');

/**
 * @type {import ('@rspack/cli').Configuration}
 */
const config = {
    entry: {
        index: path.join(__dirname, 'src/main/index.ts'),
    },
    output: {
        path: path.resolve(__dirname, 'dist'),
    }
}
Ninglo commented 10 months ago

May I be responsible for fulfilling this requirement? @Boshen

h-a-n-a commented 8 months ago

You may upgrade to the latest version ;-). It's been fixed.