Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/webpack/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
未找到ReactJS模块:Can';t解析'/static/js/myfile.js';_Reactjs_Webpack_Create React App - Fatal编程技术网

未找到ReactJS模块:Can';t解析'/static/js/myfile.js';

未找到ReactJS模块:Can';t解析'/static/js/myfile.js';,reactjs,webpack,create-react-app,Reactjs,Webpack,Create React App,我正在尝试学习React,并使用“创建React应用程序”。我现在有一个问题,我觉得很奇怪,无法解决 我有一个这样的地图结构: administratie └─ public └─ static └─ img └─ js └─ src └─ content import React, { Component } from "react"; import "./Mut.css"; import { format }

我正在尝试学习React,并使用“创建React应用程序”。我现在有一个问题,我觉得很奇怪,无法解决

我有一个这样的地图结构:

   administratie
   └─ public
      └─ static
         └─ img
         └─ js
   └─ src
      └─ content
import React, { Component } from "react";

import "./Mut.css";
import { format } from "./static/js/date.js"; // Error

class Mut extends Component {
  constructor(props) {
    super(props);
    this.state = {
      datum: ""
    };
  }

  componentDidMount() {
    let today = format(new Date());
    this.setState({
      datum: today
    });
  }

  handleChange(event) {}

  render() {
    return (
      <main>
        <img src="./static/img/administratie-logo.png" alt="logo" />  // Is rendered as it should
      </main>
    );
  }
}

export default Mut;
export function format(d) {
  let day = d.getDate().toString();
  if (day < 10) day = "0" + day;

  let month = (d.getMonth() + 1).toString();
  if (month.length === 1) month = "0" + month;

  const year = d.getFullYear().toString();

  return day + "-" + month + "-" + year;
}
在我的内容中,我有一个content.js,如下所示:

   administratie
   └─ public
      └─ static
         └─ img
         └─ js
   └─ src
      └─ content
import React, { Component } from "react";

import "./Mut.css";
import { format } from "./static/js/date.js"; // Error

class Mut extends Component {
  constructor(props) {
    super(props);
    this.state = {
      datum: ""
    };
  }

  componentDidMount() {
    let today = format(new Date());
    this.setState({
      datum: today
    });
  }

  handleChange(event) {}

  render() {
    return (
      <main>
        <img src="./static/img/administratie-logo.png" alt="logo" />  // Is rendered as it should
      </main>
    );
  }
}

export default Mut;
export function format(d) {
  let day = d.getDate().toString();
  if (day < 10) day = "0" + day;

  let month = (d.getMonth() + 1).toString();
  if (month.length === 1) month = "0" + month;

  const year = d.getFullYear().toString();

  return day + "-" + month + "-" + year;
}
date.js文件如下所示:

   administratie
   └─ public
      └─ static
         └─ img
         └─ js
   └─ src
      └─ content
import React, { Component } from "react";

import "./Mut.css";
import { format } from "./static/js/date.js"; // Error

class Mut extends Component {
  constructor(props) {
    super(props);
    this.state = {
      datum: ""
    };
  }

  componentDidMount() {
    let today = format(new Date());
    this.setState({
      datum: today
    });
  }

  handleChange(event) {}

  render() {
    return (
      <main>
        <img src="./static/img/administratie-logo.png" alt="logo" />  // Is rendered as it should
      </main>
    );
  }
}

export default Mut;
export function format(d) {
  let day = d.getDate().toString();
  if (day < 10) day = "0" + day;

  let month = (d.getMonth() + 1).toString();
  if (month.length === 1) month = "0" + month;

  const year = d.getFullYear().toString();

  return day + "-" + month + "-" + year;
}
导出函数格式(d){
let day=d.getDate().toString();
如果(天<10)天=“0”+天;
让month=(d.getMonth()+1.toString();
如果(月长===1)月=0“+月;
const year=d.getFullYear().toString();
返回日+“-”+月+“-”+年;
}

非常感谢您的任何见解

仅在
节点模块文件夹中显示URL

失败的导入语句是:

从“/static/js/date.js”/”导入{format}错误

React正在抛出错误,因为中不存在/static/js/date.js 'src''node\u modules'

要使代码正常工作,可以将date.js文件复制到'src'文件夹下的某个位置


node_modules用于通过“npm安装”下载的依赖项)

从“./public/static/js/date.js”/”导入{format}错误如果您在src文件夹中,您需要使用“.”来升级-当您在管理中时-您可以从“./public/static/js/date.js”转到public/static/jsimport{format}”;给我同样的错误OK-尝试添加“导出默认值”-而不是“导出”,为什么“/”(单点)与图像一起工作?它工作。非常感谢你对戈皮纳斯的解释。你让我开心!