Next.js Discord

Discord Forum

Appropriate Loader

Unanswered
Chukar posted this in #help-forum
Open in Discord
ChukarOP
I made a npm package but when I am trying to import it, it gives me error
"Module parse failed: Unexpected token (1:2358)
You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders"


How to fix that?

2 Replies

ChukarOP
Actually I made a npm package and build that package using esbuild

const { build } = require("esbuild");
const { dependencies, devDependencies } = require('./package.json');
const { Generator } = require('npm-dts');

new Generator({
entry: 'index.ts',
output: 'dist/index.d.ts',
}).generate();

const sharedConfig = {
entryPoints: ["index.ts"],
bundle: true,
minify: true,
external: Object.keys(dependencies).concat(Object.keys(devDependencies)),
};

build({
...sharedConfig,
platform: 'node', // for CJS
outfile: "dist/index.js",
});

build({
...sharedConfig,
outfile: "dist/index.esm.js",
platform: 'neutral', // for ESM
format: "esm",
});


This is my build.js file which I run to build my package.

Then I install the package this package in my second project using npm i "PACKAGE_NAME"