typescript 模块未在react应用程序中的npm包上找到错误,但在codesandbox上工作

shyt4zoc  于 2023-03-13  发布在  TypeScript
关注(0)|答案(1)|浏览(132)

我尝试使用react组件包在数据表中显示CSV,但发现active-table-react。我使用CRA和typescript模板创建了一个React应用程序,其中我添加了npm包,但在导入组件并运行npm start后,我收到以下错误:

ERROR in ./node_modules/active-table/dist/activeTable.js 32:0-54
Module not found: Error: Can't resolve './activeTableStyle' in '/home/user/Projects/react-table-demo/node_modules/active-table/dist'
Did you mean 'activeTableStyle.js'?
BREAKING CHANGE: The request './activeTableStyle' failed to resolve only because it was resolved as fully specified
(probably because the origin is strict EcmaScript Module, e. g. a module with javascript mimetype, a '*.mjs' file, or a '*.js' file where the package.json contains '"type": "module"').
The extension in the request is mandatory for it to be fully specified.
Add the extension to the request.

我试过使用不同版本的node和react,但是没有效果。然而,示例沙箱shown in the docs运行良好,尽管我有完全相同的配置。下面是我的代码用于比较。

// App.tsx

import React, { useState } from 'react';
import './App.css';
import { ActiveTable } from 'active-table-react';

function App() {
  const content = [
    ["Planet", "Diameter", "Mass"],
    ["Earth", 12756, 5.97],
    ["Mars", 6792, 0.642]
  ];
  return (
    <div className="App">
      <ActiveTable
        content={content}
        headerStyles={{ default: { backgroundColor: "#d6d6d630" } }}
      />
    </div>
  );
}

export default App;

我错过了什么?任何帮助都将不胜感激。Active table documentationActive table source

b09cbbtk

b09cbbtk1#

ruleswebpack.config.js中添加:

{
  test: /\.m?js/,
  resolve: {
    fullySpecified: false
  }
}

相关问题