相关疑难解决方法(0)

不允许预设文件导出对象

我有一个carousel文件,我想在其中获取index.js和构建block.build.js,所以我webpack.config.js的:

var config = {
  entry: './index.js',
  output: {
    path: __dirname,
    filename: 'block.build.js',
  },
  devServer: {
    contentBase: './Carousel'
  },
  module : {
    rules : [
      {
        test: /.js$/,
        loader: 'babel-loader',
        exclude: /node_modules/,
        query: {
          presets: ['react', 'es2015'],
          plugins: ['transform-class-properties']
        }
      }
    ]
  }
};
module.exports = config;
Run Code Online (Sandbox Code Playgroud)

package.json下面,我用的是:

{
  "name": "carousel",
  "version": "1.0.0",
  "description": "",
  "main": "webpack.config.js",
  "dependencies": {
    "@babel/core": "^7.0.0-beta.40",
    "babel-cli": "^6.26.0",
    "babel-loader": "^8.0.0-beta.0",
    "babel-plugin-lodash": "^3.3.2",
    "babel-plugin-react-transform": "^3.0.0",
    "babel-preset-react": "^6.24.1",
    "cross-env": …
Run Code Online (Sandbox Code Playgroud)

reactjs webpack babeljs

55
推荐指数
6
解决办法
5万
查看次数

Next.js-导入CSS文件不起作用

我正在创建一个带有react,redux和next.js的项目,并想在js中导入CSS文件。

我按照next.js /#cssnext-css中的说明进行操作,但是发现CSS样式无效。

我的代码如下:

pages / index.js:

import React from 'react'
import "../style.css"

class Index extends React.Component {
    render() {
        return (
            <div className="example">Hello World!</div>
        );
    }
}

export default Index
Run Code Online (Sandbox Code Playgroud)

next.config.js:

const withCSS = require('@zeit/next-css')
module.exports = withCSS()
Run Code Online (Sandbox Code Playgroud)

style.css:

.example {
    font-size: 50px;
    color: blue;
}
Run Code Online (Sandbox Code Playgroud)

package.json:

{
    "name": "my-app",
    "version": "0.1.0",
    "private": true,
    "dependencies": {
        "@zeit/next-css": "^0.1.5",
        "next": "^6.0.0",
        "react": "^16.3.2",
        "react-dom": "^16.3.2",
        "react-redux": "^5.0.7",
        "react-scripts": "1.1.4",
        "redux": "^4.0.0",
        "redux-devtools": "^3.4.1"
    },
    "scripts": { …
Run Code Online (Sandbox Code Playgroud)

javascript reactjs next.js

11
推荐指数
2
解决办法
1万
查看次数

编写TypeScript并为Browser和Node发出一个库

我有一个在Node.js和浏览器中使用的内部库.它有许多文件,与Grunt任务和不同的序言连接,一个用于浏览器,一个用于Node:

浏览器:

// dependent 3rd-party libs like Mustache are already global
window.myLib = { /*just a namespace object filled with stuff later*/ }

// then comes the plain javascript which just adds elements to myLib.
// This part is identical to that used in Node
// example:
myLib.renderPartDetail = function (...) {...};
Run Code Online (Sandbox Code Playgroud)

节点:

var Mustache = require('mustache');
var myLib = {};
module.exports = myLib;

// then comes the plain javascript which just adds elements to myLib.
// This part is …
Run Code Online (Sandbox Code Playgroud)

javascript node.js browserify typescript webpack

5
推荐指数
1
解决办法
1478
查看次数

图像未在 React 中加载

无法将图像显示为未找到错误,但我提供了它的完整路径。我不知道我哪里出错了。

class App extends React.Component {

   render() {
      return (
               <div>
                  <h1> hello</h1>    
                <img src="/home/priyanka/Finalproject/src/components/3.jpg" alt="cannot display"/>    
              </div>    
           );
         }
  }

export default App;
Run Code Online (Sandbox Code Playgroud)

javascript reactjs

5
推荐指数
3
解决办法
2万
查看次数

如何从Typescript中的package.json获取版本?

我找到了这个Q&A.

我试图从package.json中获取版本:

import { version } from './package.json';
Run Code Online (Sandbox Code Playgroud)

但它导致:

package.json' has unsupported extension. The only supported extensions are '.ts',
'.tsx', '.d.ts'.
Run Code Online (Sandbox Code Playgroud)

versioning typescript

3
推荐指数
2
解决办法
4311
查看次数