Closed cube-dan closed 4 years ago
Hello! Your issue is really strange. I need exact steps to be able to reproduce it.
Thanks for your response Jim. Exact details are where this problem gets weird. I was just pluggin' along, building out an ERD when strapi went kaboom. The last two content types that I generated with the strapi backend (/admin) were "app" and "admin".
After generating new content types through the admin backend the new items show up at the bottom of the list of content types. To put everything back in alphabetical order I usually hit refresh in the browser and get on with my life.
This time however, KABOOM!!
Hitting the backend now shows no error in the console where I started the backend using strapi start
. Here is some example output when I hit the path http://localhost:1337/admin/plugins/content-type-builder/models/admin
[2019-03-22T20:51:44.072Z] debug GET index.html (1 ms)
[2019-03-22T20:51:44.095Z] debug GET vendor.dll.js (4 ms)
[2019-03-22T20:51:44.095Z] debug GET main.js (2 ms)
[2019-03-22T20:51:44.381Z] debug GET vendor.dll.js.map (2 ms)
[2019-03-22T20:51:44.454Z] debug GET main.js.map (3 ms)
[2019-03-22T20:51:44.564Z] debug GET plugins.json (17 ms)
[2019-03-22T20:51:44.596Z] debug GET main.js (5 ms)
[2019-03-22T20:51:44.596Z] debug GET main.js (3 ms)
[2019-03-22T20:51:44.631Z] debug GET main.js (34 ms)
[2019-03-22T20:51:44.632Z] debug GET main.js (33 ms)
[2019-03-22T20:51:44.659Z] debug GET main.js (57 ms)
[2019-03-22T20:51:44.660Z] debug GET main.js (56 ms)
[2019-03-22T20:51:44.801Z] debug GET main.js (122 ms)
[2019-03-22T20:51:44.847Z] debug GET main.js.map (25 ms)
[2019-03-22T20:51:44.871Z] debug GET main.js.map (2 ms)
[2019-03-22T20:51:44.951Z] debug GET main.js.map (31 ms)
[2019-03-22T20:51:45.005Z] debug GET /content-type-builder/autoReload (12 ms)
[2019-03-22T20:51:45.006Z] debug GET main.js.map (10 ms)
[2019-03-22T20:51:45.104Z] debug GET /settings-manager/autoReload (9 ms)
[2019-03-22T20:51:45.105Z] debug GET main.js.map (6 ms)
[2019-03-22T20:51:45.356Z] debug GET main.js.map (45 ms)
[2019-03-22T20:51:45.447Z] debug GET main.js.map (6 ms)
[2019-03-22T20:51:45.448Z] debug GET /users-permissions/init (9 ms)
[2019-03-22T20:51:45.507Z] debug GET /users/me (14 ms)
[2019-03-22T20:51:45.552Z] debug GET /settings-manager/autoReload (13 ms)
[2019-03-22T20:51:45.553Z] debug GET /content-type-builder/autoReload (16 ms)
[2019-03-22T20:51:45.594Z] debug GET /content-manager/models (24 ms)
[2019-03-22T20:51:45.597Z] debug GET index.html (15 ms)
[2019-03-22T20:51:45.598Z] debug GET index.html (12 ms)
[2019-03-22T20:51:45.598Z] debug GET index.html (10 ms)
[2019-03-22T20:51:45.598Z] debug GET index.html (8 ms)
Are there any other flags that I can set when running strapi start
to get more information?
Using the theory that I used a reserved name when gI'm going to startup another project and create three content types, each with the same fields as I have in my ERD. I'll generate, in this order: department
, action
, admin
, app
.
If my theory is right — that I'm using a reserved name, or a name that should be reserved — then the backed should crash again after I've generated app
. I'll check with a hard refresh after generating each of the content types to see if the spinner of doom strikes again before I get to app
and get back to you here.
Jim,
I doubt it's related directly to my issue but something similar is showing up when using a frontend proxy (Apache) here: https://stackoverflow.com/questions/54778567/using-apache-as-a-proxy-for-backend-javascript-strapi-server
Google says this might be relevant also: https://daveceddia.com/unexpected-token-in-json-at-position-0/ ... but amma try point and click before digging into strapi's gorgeous guts.
One more thing Jim. I had the latest version of node (11.x) installed when I was generating the content types. I rolled back to 10.x and tried viewing the strapi backend again when I read the instructions in the bug report that said I needed to be on the LTS version.
Unrelated maybe?
Jim,
Found it! As soon as I add a content type called admin
and refresh the page => KABOOM!
Is there any way to delete a content type without access to the /admin pages?
edit: Nothing here? https://strapi.io/documentation/3.x.x/cli/CLI.html
-Dan
@cube-dan just delete the folder for it in api/
folder.
There are quite a number of "reserved" words that are sometimes encountered (typically a random variable or whatever) that may happen as much of the logic is built to handle a large and unknown amount of models and fields, it's bound to happen that a user picks one that JavaScript mistakes for something else.
Thanks for the suggestion @derrickmehaffy. Deleting the api/admin folder didn't work by itself. I had to also remove the "admins" attribute from all of the models that had a reference to it.
For example, in api/department/models/Department.settings.json
, I had to turn this:
{
"connection": "default",
"collectionName": "department",
"info": {
"name": "department",
"description": "Provides a City with one or more services"
},
"options": {
"timestamps": true
},
"attributes": {
"locations": {
"collection": "location",
"via": "department"
},
"admins": {
"collection": "admin",
"via": "department"
},
"description": {
"default": "",
"type": "text",
"required": true
}
}
}
into this:
{
"connection": "default",
"collectionName": "department",
"info": {
"name": "department",
"description": "Provides a City with one or more services"
},
"options": {
"timestamps": true
},
"attributes": {
"locations": {
"collection": "location",
"via": "department"
},
"description": {
"default": "",
"type": "text",
"required": true
}
}
}
Without that delete, for all of the models that related to admin, strapi will refuse to startup with this error:
[2019-03-22T22:28:06.014Z] error Something went wrong in the model `Department` with the attribute `admins`
[2019-03-22T22:28:06.016Z] error Cannot read property 'attributes' of undefined
After removing all of the references to "admins" from all models strapi is once again happy!
I guess it would be nice for strapi to refuse to create a content type for you if the creation of that content type would crash the backend. I'll open a feature request for that and the word "admin".
I'm guessing that there's something weirder happening here though as admin
isn't in javascript's list of dirty words: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Lexical_grammar#Keywords ... the real issue is probably something related to this: https://daveceddia.com/unexpected-token-in-json-at-position-0/#blame-the-server
Perhaps strapi would choke on content type names that are part of other routing paths also? For example:
plugins
, and content-manager
, from /admin/plugins/content-manager/
marketplace
from /admin/marketplace
list-plugins
from /admin/list-plugins
Anyway, I'm back in business. Thanks for the help guys!
Thank you for details.
Thank you for strapi!
I haven't tried this but resetting the admin path might allow me to use Admin as a content type name?
Instructions here: https://strapi.io/documentation/3.x.x/guides/deployment.html#_1-configure
Did you try ?
Sorry Jim, I haven't. It's the least I can do to say thanks though! I'll give it a try and get back to you here.
Jim,
Adding a content type "admin" still crashes the backend after changing the admin path to /dashboard.
Here are the steps I took and a screenshot of the result:
strapi new pathreset
localhost:1337
=> set uname to "admin" w/random passwordpathreset/config/environments/development/server.json
to /dashboardlocalhost:1337/dashboard
... so far so good!localhost:1337/dashboard
. bummer. still no love:
Please let me know if you'd like me to run a different test protocol.
One more thing Jim. I've refactored my project to get around the bug (Admin is now Editor) so please don't kill yourselves getting this fixed!
Feel free to close this issue if you'd like.
Thank you @cube-dan for this details!
I will keep this issue open because it's important thing to know or work about don't let users be able to create admin
content type.
Trying to access /admin
through webpack dev server using http-proxy-middleware
on a newly generated create react app with setupProxy.js
...
const proxy = require('http-proxy-middleware');
module.exports = function setupProxy(app) {
app.use(proxy('/admin', {
target: process.env.API_URL || 'http://localhost:1337',
secure: false,
changeOrigin: true,
}));
}
Most assets load except for a few, looks like related to webpack and strapi-helper-plugin
Informations
Node.js version: v10.15.2
NPM version: 6.4.1
Strapi version: 3.0.0-alpha.25.2
Database: mongodb v4.0.3
Operating system: macOS 10.13.6 uname says:
(Optional) Link to your Project:
What is the current behavior? console shows message:
screenshot:
Steps to reproduce the problem mind your own business while adding content types. add a content type called "app". add fields, save content type, refresh page. kaboom!
restart strapi in terminal using:
darn. still spinner of doom.
What is the expected behavior? admin backend is visible instead of spinner of doom.
Suggested solutions Start over from scratch? Make backups using git and mongodump after adding every model field? ... in all seriousness I'll probably do that anyway since strapi makes it SO easy to build out your models. Thanks for Strapi guys; fracking love the app!