Encountering a challenge while attempting to import a component from a private library that exports Typescript, we are met with the following error message:
Module parse failed: Unexpected token (82:7)
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
|
| // Types
> export type {
How can this issue be resolved? Attempts were made to explicitly include the library's node modules in the tsconfig file:
"include": [
"next-env.d.ts",
"**/*.ts",
"**/*.tsx",
"node_modules/@private-lib/*.*"
],
"exclude": [""]
However, these efforts proved unsuccessful. It appears that altering the webpack configuration of next.js might be a potential solution, but simply adding a Typescript loader did not yield positive results:
module.exports = {
webpack: (config, options) => {
config.module.rules.push({
test: /\.(ts|js)x?$/,
use: [
options.defaultLoaders.babel,
{
loader: "ts-loader",
options: {
transpileOnly: true,
experimentalWatchApi: true,
onlyCompileBundledFiles: true,
},
},
],
});
return config;
},
};
The above setup leads to the following error:
./node_modules/process/browser.js
TypeError: /home/blub/bla/website/node_modules/process/browser.js: Property left of AssignmentExpression expected node to be of a type ["LVal"] but instead got "BooleanLiteral"
If anyone has encountered similar challenges and could provide guidance on how to proceed, it would be greatly appreciated. The intricacies of this situation have proven daunting, and assistance is much needed.