我正在尝试在我的create-react-app项目中包含一些CSS.CSS来自第三方NPM包,因此它位于node_modules目录中.
我试过了:
import '/node_modules/packagename/css/styles.css';
但我得到错误:
找不到模块:您试图导入/node_modules/packagename/css/styles.css,它位于项目src /目录之外.不支持src /之外的相对导入.你可以在src /中移动它,或者从项目的node_modules /中添加一个符号链接.
我宁愿不将CSS移动到src /所以它可以通过NPM更新.我可以符号链接但是当我在Windows上开发并部署到linux时,这并不理想.
从我这里包含CSS的最佳方式是什么?
我在create-react-app中制作了一个天气应用程序.如何隐藏API密钥以便我可以提交给GitHub?
现在关键是在App.js中:const API_KEY ="123456";
我使用create-react-app样板创建了一个react应用程序,这似乎非常受欢迎,当任何文件发生变化时有时会更新热重载,有时则没有,似乎有最小持续时间或类似的东西,我'使用Ubuntu,节点版本7.0,package.json中的脚本是npm:'react-script start'我缺少的?
我正在尝试create-react-app使用Ubuntu 14.04和Nginx在数字海洋液滴上部署我的SPA.根据静态服务器部署说明,我可以在运行时使其工作serve -s build -p 4000,但是一旦我关闭终端,应用程序就会关闭.从create-react-apprepo自述文件中我不清楚如何让它永远运行,类似于永远的事情.
没有运行serve,我得到Nginx的502 Bad Gateway错误.
Nginx Conf
server {
listen 80;
server_name app.mydomain.com;
root /srv/app-name;
index index.html index.htm index.js;
access_log /var/log/nginx/node-app.access.log;
error_log /var/log/nginx/node-app.error.log;
location ~* ^.+\.(jpg|jpeg|gif|png|ico|css|zip|tgz|gz|rar|bz2|pdf|txt|tar|wav|bmp|rtf|js|flv|swf|html|htm|svg)$ {
root /srv/app-name/build;
}
location / {
proxy_pass http://127.0.0.1:4000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Access-Control-Allow-Origin *;
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
}
Run Code Online (Sandbox Code Playgroud) 根据Dan Abramov 的推文,CSS模块支持在create-react-app(CRA)中.只需要扩展module.css他的样式表来启用该功能,但这不适用于我.我的版本是1.1.4 react-scripts.如何使用CRA启用css模块?谢谢
我使用名为create-react-app的cli创建了一个react应用程序.看起来Facebook在下面做了很多事情,比如webpack等.但是,我想它可能也有一些局限性.我尝试按照本教程加载谷歌地图API.当我调试我的代码时,我可以看到谷歌地图已被成功引用.
.
但后来我点击播放,让应用程序运行完毕.我得到谷歌没有定义从webpackHotDevClient.js错误和我的应用程序崩溃.
由于webpack动态编译文件,我认为通过https加载谷歌地图有困难吗?
有什么想法吗?
我的Dockerfile使用Alpine并在全球范围内安装react-scripts。尝试安装时,失败并显示“无法获取uid / gid”错误。我在npm install -g命令中添加了“ --unsafe-perm”选项。docker容器已成功创建,但是容器中的权限已通过消息通知已安装的文件。我看到所有用户名和组都设置为1000。我尝试在安装步骤之前将以下命令添加到Dockerfile中,但这无济于事。
RUN npm -g config set user root
Run Code Online (Sandbox Code Playgroud)
建立错误
Error: could not get uid/gid
[ 'nobody', 0 ]
at /usr/local/lib/node_modules/npm/node_modules/uid-number/uid-number.js:37:16
at ChildProcess.exithandler (child_process.js:296:5)
at ChildProcess.emit (events.js:182:13)
at maybeClose (internal/child_process.js:961:16)
at Process.ChildProcess._handle.onexit (internal/child_process.js:250:5)
TypeError: Cannot read property 'get' of undefined
at errorHandler (/usr/local/lib/node_modules/npm/lib/utils/error-handler.js:205:18)
at /usr/local/lib/node_modules/npm/bin/npm-cli.js:76:20
at cb (/usr/local/lib/node_modules/npm/lib/npm.js:228:22)
at /usr/local/lib/node_modules/npm/lib/npm.js:266:24
at /usr/local/lib/node_modules/npm/lib/config/core.js:83:7
at Array.forEach (<anonymous>)
at /usr/local/lib/node_modules/npm/lib/config/core.js:82:13
at f (/usr/local/lib/node_modules/npm/node_modules/once/once.js:25:25)
at afterExtras (/usr/local/lib/node_modules/npm/lib/config/core.js:173:20)
at Conf.<anonymous> (/usr/local/lib/node_modules/npm/lib/config/core.js:231:22)
/usr/local/lib/node_modules/npm/lib/utils/error-handler.js:205
if (npm.config.get('json')) {
^
TypeError: Cannot read property 'get' …Run Code Online (Sandbox Code Playgroud) 我正在尝试在 create-reat-app 中使用 react-router 和 reactstrap。在路由页面中,我需要使用 reactstrap 的状态,因此我将路由器从变量转换为类。我收到此警告:警告: validateDOMNesting(...):
<a> cannot appear as a descendant of <a>.
我不知道该怎么做?,我需要使用 reactstrap 来设置路由器导航的样式,所以我做了你在下面看到的。
由于很多原因,这不起作用:
<NavLink componentClass={Link} href="/contact" to="/contact" active={location.pathname === '/contact'}>anywords</NavLink>
Run Code Online (Sandbox Code Playgroud)
<Navbar dark id="RouterNavbar" expand="md">
<NavbarBrand id="NavBrand"href="#x"><ul>(a bunch of li not relevant)</ul></NavbarBrand>
<NavbarToggler id="NavBarToggler" onClick={this.toggle1.bind(this)} />
<Collapse isOpen={this.state.isOpen1} navbar>
<Nav className="ml-auto" navbar>
<NavItem>
<NavLink href="#x"><Link id="RouterNavLink" style={None} to="/contact">anywords</Link></NavLink>
</NavItem>
(then just more of the above)
Run Code Online (Sandbox Code Playgroud)
除了几个 li 随机靠近彼此,我有时不得不刷新页面而不是正常行为(自动刷新)和我在控制台中收到的警告消息,没有什么不好的事情发生,但是当我读到这个的时候问题我发现我不应该这样做。
当我尝试使用 创建新的 React 应用程序时npx create-react-app example_app,出现此错误
[您的缓存文件夹包含根拥有的文件,这是由于以前版本的 npm 中的一个错误,该错误已被解决 sudo chown -R 0:0 "/root/.npm"]
我甚至尝试重新安装create-react-app再次使用npm i create-react-app,这是给同类的
错误。
我在搜索之后假设这是由于某些权限问题。我当前的用户无权访问我的用户名/home/shubham/.npm在哪里shubham,但我对此不太确定。
我试图使用chown命令来解决这个错误
sudo chown -R <username>:<groupname> /home/shubham/.npm"
Run Code Online (Sandbox Code Playgroud)
where <username>isShubham和<groupame>is 1000,但它仍然无法正常工作。
请求人们帮助我。如果您需要更多信息,请告诉我。
尝试使用“create-react-app”创建新项目时,出现此错误
Installing packages. This might take a couple of minutes.
Installing react, react-dom, and react-scripts with cra-template...
npm ERR! code E404
npm ERR! 404 Not Found - GET https://registry.npmjs.org/@typescript-eslint%2feslint-plugin - Not found
npm ERR! 404
npm ERR! 404 '@typescript-eslint/eslint-plugin@^2.10.0' is not in the npm registry.
npm ERR! 404 You should bug the author to publish it (or use the name yourself!)
npm ERR! 404 It was specified as a dependency of 'react-scripts'
npm ERR! 404
npm ERR! 404 Note that …Run Code Online (Sandbox Code Playgroud) create-react-app ×10
reactjs ×8
node.js ×2
npm ×2
api ×1
api-key ×1
css-modules ×1
deployment ×1
docker ×1
github ×1
google-maps ×1
javascript ×1
linux ×1
nginx ×1
react-router ×1
reactstrap ×1
webpack ×1