Issue with Path Alias Functionality in Bun Project Despite Accurate Configuration

I followed a guide to configure path alias at , but unfortunately, it's not working as expected.

Recently I started a new Bun project with the intention of migrating a Node app to Bun. Here are the steps I took:

  1. Create a directory and initialize the Bun project by running

    mkdir bun-test && cd bun-test && bun init

  2. After initializing the project, I added the following code to tsconfig.ts

{
  "compilerOptions": {
    ...
    "baseUrl": "./src",
    "paths": {
      "config": ["./src/config/appConfig.ts"]
    }
  }
}
  1. Create a file named src/config/appConfig.ts
export default {
  message: "My first bun application"
};
  1. Make changes in src/index.ts.
import appConfig from "config";

console.log(appConfig.message);
  1. Although VSCode intellisense is resolving the paths correctly, when I run the app using bun run ./src, it throws an error
error: Cannot find package "config" from "/bun-test/src/index.ts"

Bun v1.1.29 (Linux x64)

I'm facing this issue, what could be causing it? Am I missing any steps? Your help would be appreciated!

Answer №1

After spending half a day searching, I finally stumbled upon the answer at this GitHub repository.

A big shoutout to JLarky for the helpful note: When using bun dev, it acts as a script runner while Vite runs in Node. However, by running bun --bun dev, Bun JavaScript runtime is utilized to run Vite.

I was able to successfully execute my code with bun --bun run ./src

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Changing the style.backgroundImage property overrides any image transition effects

I am currently working on creating a button for a player. You can check out the video (here) The button works, but in order to give it a "pressed" effect, I have to change its background-image on click. However, this action seems to override the transitio ...

Having constant problems with ngModel twoway binding. Any suggestions on how to successfully bind to a property in order to update an api link?

I am attempting to implement two-way binding in order to dynamically change the API endpoint when a button is clicked. The value attribute of the button should be used as part of the API URL string. I tried following an example in the Hero Angular App, bu ...

Nuxt 3 TypeScript is throwing an error because the export named 'default' is missing from the requested module at '/_nuxt/models/component/blog/BlogPage.interface.ts'

While working on my Nuxt 3 project with Typescript, I encountered an error when importing Typescript models from components: The requested module '/_nuxt/models/component/blog/BlogPage.interface.ts' does not provide an export named 'default& ...

Tips for integrating search functionality with vanilla javascript?

My contact list app displays contact details and I am looking to add a search feature based on the contact's name. This functionality will allow the user to dynamically filter the contact list as they type in a specific name. Here is a snippet of the ...

Transferring information to the server with JSON in the Codeigniter framework

I have a JavaScript array (unitdata_set) that I need to send to the server for database processing using Codeigniter. JavaScript Array (unitdata_set):- [{"unit_id":"13","unit_title":"Testsdsdf","unit_max_occupancy":"3","unit_no":"1","unit_no_adults":"1", ...

What is the process for accessing jQuery methods in Node.js?

When working on the client side, using Object.keys($.fn) (or Object.keys(jQuery.fn)) is a simple way to retrieve jQuery functions as an array. But how can I achieve the same result of getting this array with the jquery package from npm? I attempted: re ...

I am experiencing difficulty with implementing a page break within the <tr> and <tbody> elements

Below is the code I am working with: {% for item in child.items %} {%set ns.count = ns.count + 1%} <tbody style="page-break-inside: avoid"> <tr style="page-break-inside: avoid"> ...

Tips for enforcing lang="ts" in script tags using an ESLint rule in Vue

Seeking a method to ensure that all team members working on our code base utilize TypeScript for Single File Components. The components are all designed with TypeScript, therefore disabling JavaScript is a viable solution. I initially considered implement ...

The function responsible for displaying totals in the footer is producing inaccurate figures. What steps can be taken to address this

I am working with an Angular Material table that looks like this: <table mat-table [dataSource]="mixDetails" matSort matSortActive="index" matSortDirection="asc"> <ng-container matColumnDef="select"> < ...

When comparing TypeScript index signatures to Record<Keys, Type> return type, the focus is on handling objects with unspecified properties

I have a function called getQueryParams that takes a string as input and returns an object with unknown properties: function getQueryParams(s) { if (!s || typeof s !== 'string' || s.length < 2) { return {} } return s .substr(1) ...

Check the integrity of a combined data type with Joi

I have a union type called PaymentTerm: type PaymentTerm = | { type: 'AdvancePayment' } | { type: 'PaymentGoal'; netPaymentDays: number } To validate it, I am using the Joi.alternatives method: Joi.object({ type: Joi.stri ...

Is it acceptable to reference all JS files in index.html in Angular?

Just dove into my first AngularJS project! Following a tutorial where they put everything in one controller, but now I want to separate controllers and services. I managed to split them into different JS files, but is it best practice to list all these f ...

AngularJS: Issue with Variable Value Rendering

I recently started working with Angular. In my JavaScript file, I have the following code: App.controller('ProductController', ['$scope', 'ProductService', function ($scope, ProductService) { console.clear(); console. ...

No action is triggered after submitting AJAX data in a WordPress environment

I'm currently working on developing a WordPress plugin that requires querying the database. However, I am facing challenges in getting it to function properly. Here is the code snippet that I have attempted: jQuery('#demo_ajax').submit(func ...

Step-by-step guide on deleting an entire row from a PHP webpage

I have removed a row from the database, but now I need to also remove it from the interface on my PHP page. Any suggestions or assistance would be greatly appreciated. Here is a snippet of mypage.php: <tr> <td><?php echo $row[' ...

Developing a versatile tool to eliminate duplicate items from arrays in JavaScript

Currently, I am in the process of developing a generic utility function that can eliminate duplicates from an array in JavaScript. The snippet below showcases the code where the desired outcome is successfully achieved. My goal is to transform this into ...

"What could be causing my React Native app to build without any issues even though the TypeScript compiler is throwing

Recently, I decided to explore TypeScript in combination with Expo. I took the time to set up linter and formatter integrations like typescript-eslint to help me catch errors while coding. Periodically, I run npx tsc to ensure my code compiles correctly an ...

Troubleshooting the Three.js installation and modules on a local server issue

Seeking assistance from experienced individuals on this platform for my three.js issue. The current problem I am facing is the inability to run the three.js library properly on my localhost, resulting in a white screen. Here are my files: My JavaScript c ...

Is it possible to send an HTTP request from the renderer process to the main process in Electron?

Currently, I am in the midst of developing an electron video player project. My main objective is to stream video from a readable stream to an HTML video-tag. I am exploring different solutions and strategies to achieve this goal. In particular, I am cur ...

Traverse the data() object in jQuery to retrieve both keys and values simultaneously

I have a data() object with some JSON content. Is there a way to iterate through the object and extract each key and value pair? Here's my current code snippet: function getFigures() { var propertyValue = getUrlVars()["propertyValue"]; $.getJSON( ...