我正在尝试使用Webpack 2.2.1在cycle.js中运行Hello World应用程序

我收到此错误:


  找不到./app/index.js模块中的错误:错误:无法解决
  '/ Users / Ben / proj / sb_vol_calc / frontend / app'中的'@ cycle / run'@
  ./app/index.js 7:11-32 @多
  webpack-dev-server / client?http://localhost:3000 ./app/index


这是我的webpack.config.js:

   var path = require('path')
var webpack = require('webpack')

module.exports = {
  devtool: 'eval',
  entry: [
    'webpack-dev-server/client?http://localhost:3000',
    './app/index'
  ],
  output: {
    path: path.join(__dirname, 'dist'),
    filename: 'bundle.js'
  },
  module: {
    rules: [
      {
        test: /\.js$/,
        use: {
          loader: 'babel-loader'
        }
      }
    ]
  },
  resolve: {
    extensions: ['.js'],
    modules: [
      path.join(__dirname, 'src'),
      "node_modules"
    ]
  }
}


package.json:

{
  "name": "xxx",
  "version": "1.0.0",
  "main": "index.js",
  "license": "MIT",
  "scripts": {
    "start": "node server.js",
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "babel": {
    "presets": [
      "es2015",
      "react",
      "stage-0"
    ]
  },
  "devDependencies": {
    "babel-core": "^6.23.1",
    "babel-loader": "^6.3.2",
    "babel-preset-es2015": "^6.22.0",
    "babel-preset-react": "^6.23.0",
    "babel-preset-stage-0": "^6.22.0",
    "webpack": "^2.2.1",
    "webpack-dev-server": "^2.4.1"
  },
  "dependencies": {
    "@cycle/dom": "^14.3.0",
    "@cycle/xstream-run": "^4.2.0",
    "xstream": "^10.2.0"
  }
}


我已经运行npm install。它现在应该工作吗?还是我错过了什么?

index.js:

import xs from 'xstream';
import {run} from '@cycle/run';
import {makeDOMDriver, h1} from '@cycle/dom';

function main() {
  const sinks = {
    DOM: xs.periodic(1000).map(i =>
      h1('' + i + ' seconds elapsed')
    )
  };
  return sinks;
}

const drivers = {
  DOM: makeDOMDriver('#root')
};

run(main, drivers);

最佳答案

您没有安装@cycle/run作为依赖项,而是安装了@cycle/xstream-run。因此,您必须从中导入run

import {run} from '@cycle/xstream-run';


根据latest release@cycle/xstream-run已重命名为@cycle/run,因此您可能应该开始使用它。您需要做的就是安装它:

npm install --save @cycle/run

关于javascript - 找不到模块:错误:无法解析“@ cycle/run” webpack 2.2.1,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/42432053/

10-13 00:34