nx
nx copied to clipboard
React assets library import is not working
Current Behavior
I made an asset library on my monorepo and try to import it in my react app but it's not working
Expected Behavior
I succesfully imported my asset library on my Next App by adding these lines in my project.json
:
in targets.build.options
"assets": [
{
"input": "libs/common/assets/src/lib",
"glob": "**/*",
"output": "assets"
}
]
My asset library is copied in my NextJS asset folder
I assume there is the similar feature with basic React apps but adding the exact same lines in my project.json
of my React app doesn't work...
Failure Logs
No error messages...
Environment
the project.json
of my React app :
{
"$schema": "../../node_modules/nx/schemas/project-schema.json",
"sourceRoot": "apps/sellers/src",
"projectType": "application",
"implicitDependencies": ["common-assets"],
"targets": {
"build": {
"executor": "@nrwl/web:webpack",
"outputs": ["{options.outputPath}"],
"defaultConfiguration": "production",
"options": {
"compiler": "babel",
"outputPath": "dist/apps/sellers",
"index": "apps/sellers/src/index.html",
"baseHref": "/",
"main": "apps/sellers/src/main.tsx",
"polyfills": "apps/sellers/src/polyfills.ts",
"tsConfig": "apps/sellers/tsconfig.app.json",
"assets": [
"apps/sellers/src/favicon.ico",
"apps/sellers/src/assets",
{
"input": "libs/common/assets/src/lib",
"glob": "**/*",
"output": "apps/sellers/src/assets"
}
],
"stylePreprocessorOptions": {
"includePaths": ["apps/sellers/src/assets/styles"]
},
"styles": ["apps/sellers/src/assets/styles/globals.scss"],
"scripts": [],
"webpackConfig": "@nrwl/react/plugins/webpack"
},
"configurations": {
"development": {
"extractLicenses": false,
"optimization": false,
"sourceMap": true,
"vendorChunk": true
},
"production": {
"fileReplacements": [
{
"replace": "apps/sellers/src/environments/environment.ts",
"with": "apps/sellers/src/environments/environment.prod.ts"
}
],
"optimization": true,
"outputHashing": "all",
"sourceMap": false,
"namedChunks": false,
"extractLicenses": true,
"vendorChunk": false
}
}
},
"serve": {
"executor": "@nrwl/web:dev-server",
"defaultConfiguration": "development",
"options": {
"buildTarget": "sellers:build",
"hmr": true
},
"configurations": {
"development": {
"buildTarget": "sellers:build:development"
},
"production": {
"buildTarget": "sellers:build:production",
"hmr": false
}
}
},
"lint": {
"executor": "@nrwl/linter:eslint",
"outputs": ["{options.outputFile}"],
"options": {
"lintFilePatterns": ["apps/sellers/**/*.{ts,tsx,js,jsx}"]
}
},
"test": {
"executor": "@nrwl/jest:jest",
"outputs": ["coverage/apps/sellers"],
"options": {
"jestConfig": "apps/sellers/jest.config.ts",
"passWithNoTests": true
}
}
},
"tags": []
}
nx report :
Node : 16.15.1
OS : darwin arm64
yarn : 1.22.19
nx : 14.5.4
@nrwl/angular : Not Found
@nrwl/cypress : 14.5.4
@nrwl/detox : Not Found
@nrwl/devkit : 14.5.4
@nrwl/eslint-plugin-nx : 14.5.4
@nrwl/express : Not Found
@nrwl/jest : 14.5.4
@nrwl/js : 14.5.4
@nrwl/linter : 14.5.4
@nrwl/nest : 14.5.4
@nrwl/next : 14.5.4
@nrwl/node : 14.5.4
@nrwl/nx-cloud : 14.3.0
@nrwl/nx-plugin : Not Found
@nrwl/react : 14.5.4
@nrwl/react-native : Not Found
@nrwl/schematics : Not Found
@nrwl/storybook : 14.5.4
@nrwl/web : 14.5.4
@nrwl/workspace : 14.5.4
typescript : 4.7.4
---------------------------------------
Community plugins:
Hi, I could not reproduce the issue: https://github.com/FrozenPandaz/nx-bugs/tree/repro-11846
My assets get properly outputted into my dist.
Could you retry with the latest version and if that doesn't work, can you provide a repo we can pull down please?
Sure, here it is : https://github.com/LouisLecouturier/resplyNx
But I don't see your asset copied in your asset folder of your React app in your repo
My problem is that I can't use my asset library inside my react app
This issue has been automatically marked as stale because it hasn't had any recent activity. It will be closed in 14 days if no further activity occurs. If we missed this issue please reply to keep it active. Thanks for being a part of the Nx community! 🙏
I'm having exact same issue with a next app we are migrating, we have some assets at repo root level, after moving from "@nrwl/next": "13.8.8", to "@nrwl/next": "14.8.3", the assets are not longer served by the next app, however if a I build the app they are loaded, under project json we reuse these assets using this config:
"options": {
"root": "apps/com",
"outputPath": "dist/apps/com",
"assets": [
{
"glob": "**/*",
"input": "assets/fonts/",
"output": "/assets/fonts/"
},
{
"glob": "**/*",
"input": "styles/",
"output": "/styles/"
},
{
"glob": "**/*",
"input": "assets/icons/",
"output": "/assets/icons/"
},
{
"glob": "**/*",
"input": "assets/scripts/",
"output": "/assets/scripts/"
}
]
Found there is a big difference between this plugin versions when serving:
old
https://github.com/nrwl/nx/blob/1f534317d03251deaf231e2f5f3de0905b4627e7/packages/next/src/builders/server/lib/default-server.ts
vrs
latest
https://github.com/nrwl/nx/blob/master/packages/next/src/executors/server/lib/default-server.ts
This issue has been closed for more than 30 days. If this issue is still occuring, please open a new issue with more recent context.