I'm trying to import a functions from a dependency to my next/react functional component, but somehow I keep getting the following error:
SyntaxError: Unexpected token 'export'
That's the function I'm trying to import:
export function classes(...args) {
const list = [];
for (let i = 0; i < args.length; i++) {
const entry = args[i];
if (typeof entry === "string") {
list.push(entry);
}
else {
for (let key in entry) {
if (entry[key]) {
list.push(key);
}
}
}
}
return list.join(" ");
There additionally is a classes.d.ts
next to the classes.js
above:
export declare function classes(...args: Array<string | {
[key: string]: any;
}>): string;
Exporting this code identically from within the project works fine, but not when I use an external library from node_modules
. How so?
Read about next-transpile-module
, but haven't been able to make it run with this one either.
The only way to make the import work is using relative paths ../../node_modules/thedependency/class
- how can I make it work properly?