这是我的package.json文件
{
"name": "deep-playground-prototype",
"version": "2016.3.10",
"description": "",
"private": true,
"scripts": {
"clean": "rimraf dist",
"start": "npm run serve-watch",
"prep": "browserify src/csv.ts -p [tsify] | uglifyjs -c > csv.js && copyfiles analytics.js dist && concat node_modules/material-design-lite/material.min.js node_modules/seedrandom/seedrandom.min.js csv.js > dist/lib.js",
"build-css": "copyfiles fonts.css dist && concat node_modules/material-design-lite/material.min.css styles.css > dist/bundle.css",
"watch-css": "concat node_modules/material-design-lite/material.min.css styles.css -o dist/bundle.css",
"build-html": "copyfiles index.html dist",
"watch-html": "concat index.html -o dist/index.html",
"watch-js": "watchify src/playground.ts -p [tsify] -v --debug -o dist/bundle.js",
"build-js": "browserify src/playground.ts -p [tsify] | uglifyjs -c > dist/bundle.js",
"build": "npm run prep && npm run build-js && npm run build-css && npm run build-html",
"watch": "npm run prep && concurrently \"npm run watch-js\" \"npm run watch-css\" \"npm run watch-html\"",
"serve": "http-server -o -c-1 dist/",
"serve-watch": "concurrently \"http-server -o -c-1 dist/\" \"npm run watch\""
},
"devDependencies": {
"@types/d3": "^3.5.41",
"concat": "^1.0.3",
"concurrently": "3.1.0",
"copyfiles": "1.0.0",
"http-server": "^0.11.1",
"rimraf": "2.5.4",
"tsify": "^4.0.0",
"typescript": "^2.9",
"uglify-js": "^2.8.29",
"watchify": "^3.11.0"
},
"dependencies": {
"@types/jquery": "^3.3.27",
"csv-parse": "^4.2.0",
"csvtojson": "^2.0.8",
"d3": "^3.5.16",
"https-proxy-agent": "^2.2.1",
"material-design-lite": "^1.3.0",
"seedrandom": "^2.4.3",
"typings": "^2.1.1"
}
}csv.ts文件是:
import {csv} from 'd3';
async function delay(ms: number) {
return new Promise( resolve => setTimeout(resolve, ms) );
}
export let train = [];
(async()=>{console.log('before delay');csv("training.csv",function(error,data){train = data});await delay(1000);console.log('after delay')})();我首先尝试将数据加载到一个名为train的变量中。然后,我尝试将它从lib.js文件中拉到程序中:
import {train} from 'lib';但是在编译后得到以下错误:
TypeScript错误:src/datet.ts(17,21):错误TS2307:无法找到模块'lib‘。
在这个过程中,我错过了一些东西。
发布于 2018-12-18 12:20:13
除非更改模块加载逻辑,否则可能需要一个相对导入路径:
import { train } from './lib'; // Assuming same folder, otherwise adjust path如果'lib'是一个可识别的模块,那么它就可以工作,例如安装到node_modules上的依赖项。
https://stackoverflow.com/questions/53832121
复制相似问题