'Next.js does not recognize custom npm package
Here's my personal custom package structure:
package.json
Posts.js
And here's the content of Posts.js:
const Posts = () => {
return <div>List of posts</div>
}
export default Posts;
I publish this to my GitHub Package Registry and I install it to a next.js app using npm install @myOwnerName:blog.
And I can verify that it's been installed.
However, when I want to use it using import Posts from '@myOwnerName/blog/Posts', I see this error:
Failed to compile
./node_modules/@myOwnerUser/blog/Posts.js
Module parse failed: Unexpected token (2:11)
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
| const Posts = () => {
> return <div>List of posts</div>
| }
|
What have I done wrong?
Solution 1:[1]
Before publish npm package, we should compile react components to es-module.
So, in webpack configuration, unknown file type error.
I think, it is more correct way to compile react component before publish it.
Solution 2:[2]
You need to first import the DataTable into the cells and then create a Table from those cells.
For example, like this:
// Sample DataTable.
var dataTable = new DataTable();
dataTable.Columns.Add("ID", typeof(int));
dataTable.Columns.Add("FirstName", typeof(string));
dataTable.Columns.Add("LastName", typeof(string));
dataTable.Rows.Add(new object[] { 100, "John", "Doe" });
dataTable.Rows.Add(new object[] { 101, "Fred", "Nurk" });
dataTable.Rows.Add(new object[] { 103, "Hans", "Meier" });
dataTable.Rows.Add(new object[] { 104, "Ivan", "Horvat" });
dataTable.Rows.Add(new object[] { 105, "Jean", "Dupont" });
dataTable.Rows.Add(new object[] { 106, "Mario", "Rossi" });
// New ExcelFile or use ExcelFile.Load for existing file.
var workbook = new ExcelFile();
var worksheet = workbook.Worksheets.Add("Sheet1");
// Insert DataTable to an Excel worksheet.
var options = new InsertDataTableOptions() { ColumnHeaders = true };
worksheet.InsertDataTable(dataTable, options);
// Create an Excel table.
string range = $"A1:{CellRange.RowColumnToPosition(dataTable.Rows.Count, dataTable.Columns.Count - 1)}";
var table = worksheet.Tables.Add("Table1", range, true);
table.BuiltInStyle = BuiltInTableStyleName.TableStyleLight10;
// Save as XLSX file.
workbook.Save("output.xlsx");
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Brain Hong |
| Solution 2 | Mario Z |
