Я хотел бы использовать библиотеку облегченных диаграмм с модулем ES.
Я хотел бы использовать облегченные диаграммы в браузере, поэтому я следовал инструкциям документа
https://tradingview.github.io/lightweig ... ng-a-chart
import { createChart } from 'lightweight-charts';
но ошибка Uncaught TypeError: спецификатор «lightweight-charts» был пустым спецификатором, но не был переназначен ни на что. Спецификаторы относительных модулей должны начинаться с «./», «../» или «/».
Также у меня есть импорт date-fns и csv-parse с импортом модуля es, например:
import { parse } from './node_modules/csv-parse/dist/esm/sync.js'
import * as datefns from "./node_modules/date-fns/index.js"
Эти модули работают, но облегченные диаграммы работают неправильно.
Как исправить ошибку?
Мои package.json и tsconfig.json следуют.
tsconfig.json:
{
// Visit https://aka.ms/tsconfig to read more about this file
"compilerOptions": {
// File Layout
// "rootDir": "./src",
// "outDir": "./dist",
// Environment Settings
// See also https://aka.ms/tsconfig/module
"module": "es2022",
"target": "es2022",
"types": [],
"moduleResolution": "bundler",
// For nodejs:
// "lib": ["esnext"],
// "types": ["node"],
// and npm install -D @types/node
// Other Outputs
"sourceMap": true,
"declaration": true,
"declarationMap": true,
// Stricter Typechecking Options
"noUncheckedIndexedAccess": true,
"exactOptionalPropertyTypes": true,
// Style Options
// "noImplicitReturns": true,
// "noImplicitOverride": true,
// "noUnusedLocals": true,
// "noUnusedParameters": true,
// "noFallthroughCasesInSwitch": true,
// "noPropertyAccessFromIndexSignature": true,
// Recommended Options
"strict": true,
"jsx": "react-jsx",
"verbatimModuleSyntax": true,
"isolatedModules": true,
"noUncheckedSideEffectImports": true,
"moduleDetection": "force",
"skipLibCheck": true
}
}
package.json:
{
"name": "my_charts",
"version": "1.0.0",
"description": "",
"license": "ISC",
"author": "",
"type": "module",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"devDependencies": {
"typescript": "^5.9.3"
},
"dependencies": {
"csv-parse": "^6.1.0",
"date-fns": "^4.1.0",
"lightweight-charts": "^5.0.9"
}
}
Подробнее здесь: https://stackoverflow.com/questions/797 ... module-way