1

I want to build a package and upload it to npm so I tried to create a demo package first. I used this repo as a starter package: https://github.com/wobsoriano/vite-react-tailwind-starter

and updated the build script to this

  "build-test": "esbuild src/App.tsx --bundle --minify  --outfile=src/dist/index.js",

and the App.tsx i updated to this

import React from "react";
import "./index.css";

const App = () => {
  return <div>My Dummy</div>;
};

export default App;

Then I tried to build it and import it in my main.tsx like this:

import React from "react";
import ReactDOM from "react-dom";
import App from "./dist/index.js";

ReactDOM.render(
  <React.StrictMode>
    <App />
  </React.StrictMode>,
  document.getElementById("root")
);

And then I get this error:

The requested module '/src/dist/index.js' does not provide an export named 'default

1 Answer 1

1

I only can give you a quick manual fix. For some reason the index.js file has no "export default" keywords, but you can open the src\dist\index.js file and you can just insert the "export default " at the very begin. So the begin will look like this:

export default ()=>{var K=Object.create;var _=Object.define.

Because the whole index.js just a function, you can do this.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.