在 reactjs 中无法识别库
library not recognised in reactjs
clicke here to see pondjs folder inside node-modulesI've installed pondjs(https://www.npmjs.com/package/pondjs) 在我的 React 应用程序中使用 npm install pondjs --save。它也存在于 package.json 中。我不明白为什么在应用程序中。当我在做 js 时 :
import { TimeSeries , TimeRange} from 'pondjs';
它说模块没有安装,因此无法识别它的功能。
此外,我有一个 js 文件,其中包含大量对象形式的数据,我正在尝试使用 :
在 App.js 中导入该文件
import pathtofile/inputdata.js';
并存储在如下变量中:
var input_data = data;
在 React App.js 文件中这是正确的做法吗?请推荐
因为您的问题分为两部分。我会按顺序回答的。
您的第一个问题是您无法调用 pondjs
的方法,即使您安装了它。
为此,请确保 node_modules
文件夹中有您的 pondjs
文件夹,当您在存储库中安装某些软件包时,将创建该文件夹。
EDIT :
Are you only having issues with pondjs
or are you facing issues with
all packages?
If you can find the installed package in node_modules
folder and is
facing the same issue for all packages, upgrade npm
. Your problem is
that it doesn't search in the right folder. Try upgrading npm
so
that it places files in the right spots.
If it's only for pondjs
issue might be with the package rather that
with your npm
package. Make sure you read documentation right and
are doing in the right way.
来到你的第二个问题。
在其他文件中导出您要访问的变量。
var obj = {
a : [1, 2, 3, 4],
b : { c : 'Hello World!' }
}
export var obj;
然后这样称呼它,
import { obj } from './path/to/the/file.js'
对于 pondjs,我的代码适用于 Sublime Text 和终端。可能是 Webstorm IDE 无法识别 Pondjs 或其他东西。
使用 require
而不是 import
。
const { TimeSeries, TimeRange } = require('pondjs');
clicke here to see pondjs folder inside node-modulesI've installed pondjs(https://www.npmjs.com/package/pondjs) 在我的 React 应用程序中使用 npm install pondjs --save。它也存在于 package.json 中。我不明白为什么在应用程序中。当我在做 js 时 :
import { TimeSeries , TimeRange} from 'pondjs';
它说模块没有安装,因此无法识别它的功能。
此外,我有一个 js 文件,其中包含大量对象形式的数据,我正在尝试使用 :
在 App.js 中导入该文件import pathtofile/inputdata.js';
并存储在如下变量中:
var input_data = data;
在 React App.js 文件中这是正确的做法吗?请推荐
因为您的问题分为两部分。我会按顺序回答的。
您的第一个问题是您无法调用 pondjs
的方法,即使您安装了它。
为此,请确保 node_modules
文件夹中有您的 pondjs
文件夹,当您在存储库中安装某些软件包时,将创建该文件夹。
EDIT :
Are you only having issues with
pondjs
or are you facing issues with all packages?If you can find the installed package in
node_modules
folder and is facing the same issue for all packages, upgradenpm
. Your problem is that it doesn't search in the right folder. Try upgradingnpm
so that it places files in the right spots.If it's only for
pondjs
issue might be with the package rather that with yournpm
package. Make sure you read documentation right and are doing in the right way.
来到你的第二个问题。
在其他文件中导出您要访问的变量。
var obj = {
a : [1, 2, 3, 4],
b : { c : 'Hello World!' }
}
export var obj;
然后这样称呼它,
import { obj } from './path/to/the/file.js'
对于 pondjs,我的代码适用于 Sublime Text 和终端。可能是 Webstorm IDE 无法识别 Pondjs 或其他东西。
使用 require
而不是 import
。
const { TimeSeries, TimeRange } = require('pondjs');