`npm start`抱怨“缺少脚本:启动”,没有运行节点(`npm start` complains “missing script: start”, without running node)
我的NPM包中有以下文件:
package.json
:{ "name": "npm-start", "version": "1.0.0", "description": "", "main": "index.js", "scripts": { "test": "echo \"Error: no test specified\" && exit 1" }, "author": "", "license": "ISC" }
index.js
console.log('Hello world!');
当我尝试运行
npm start
,收到一条错误消息:> npm start npm ERR! missing script: start
好的,这是真的:我在
"scripts"
对象中没有"start"
属性。 但NPM的CLI文档声称这是关于npm start
:如果在
"scripts"
对象上未指定"start"
属性,则它将运行node server.js
。为什么NPM让我失望? 是不是应该在这种情况下调用
node
? 我错过了什么吗? (当然,手动调用节点工作正常)。如果相关:
> npm -version 5.3.0
I have the following files in my NPM package:
package.json
:{ "name": "npm-start", "version": "1.0.0", "description": "", "main": "index.js", "scripts": { "test": "echo \"Error: no test specified\" && exit 1" }, "author": "", "license": "ISC" }
index.js
console.log('Hello world!');
When I try to run
npm start
, I get an error message:> npm start npm ERR! missing script: start
Okay, it's true: I don't have a
"start"
property in"scripts"
object. But NPM's CLI Documentation claims this aboutnpm start
:If no
"start"
property is specified on the"scripts"
object, it will runnode server.js
.Why is NPM failing me? Isn't it supposed to invoke
node
in this scenario? Am I missing something? (Of course, manually invoking node works fine).In case it's relevant:
> npm -version 5.3.0
原文:https://stackoverflow.com/questions/47219615
最满意答案
我发现它,问题不在于Multi模块Graldle,Spring引导或Oauth2相关。 实际上,这是由于Gradle的src集合配置,其中Java应该位于Java src集文件夹中,而Kotlin位于Java src集文件夹中:
sourceSets { main.java.srcDirs += 'src/main/java' main.kotlin.srcDirs += 'src/main/kotlin' }
正如Will Humphreys在他上面的评论中所说的那样,IntelliJ需要所有源代码集并运行该应用程序。 但是,通过Gradle构建jar时,这些源代码集更加严格。 我在我的Kotlin src集合中有一个Java文件,这对IntelliJ来说没有问题。 但是由Gradle创建的jar考虑到了
build.gralde
文件中定义的源代码集,它们更严格。我用下面的代码找到了我的缺失bean问题:
@Bean public CommandLineRunner commandLineRunner(ApplicationContext ctx) { return args -> { System.out.println("Let's inspect the beans provided by Spring Boot:"); String[] beanNames = ctx.getBeanDefinitionNames(); Arrays.sort(beanNames); for (String beanName : beanNames) { System.out.println(beanName); } }; }
我错过的Bean被称为
AuthenticationController
,它是一个@RestController
,并且对于我的验证代码至关重要。I found it, the problem was not Multi module Graldle, Spring boot, or Oauth2 related. In fact it was due to a src set config of Gradle, where Java was supposed to be in a Java src set folder, and Kotlin in a Java src set folder:
sourceSets { main.java.srcDirs += 'src/main/java' main.kotlin.srcDirs += 'src/main/kotlin' }
As Will Humphreys stated in his comment above, IntelliJ takes all source sets, and runs the app. However, when building the jar via Gradle, these source sets are stricter. I had a Java file in my Kotlin src set, which is no problem for IntelliJ. But the jar created by Gradle takes into account the source sets as defined in the
build.gralde
file, which are stricter.I found my missing bean issue with the code below:
@Bean public CommandLineRunner commandLineRunner(ApplicationContext ctx) { return args -> { System.out.println("Let's inspect the beans provided by Spring Boot:"); String[] beanNames = ctx.getBeanDefinitionNames(); Arrays.sort(beanNames); for (String beanName : beanNames) { System.out.println(beanName); } }; }
The Bean I missed was called
AuthenticationController
, which is a@RestController
, and kinda crucial for my authentication code.
相关问答
更多-
Gradle Multi Module jar(Gradle Multi Module jar)[2023-02-28]
您可以尝试在根构建脚本中创建Jar类型的自定义任务,该脚本将包括所有子项目的所有类或仅包含许多子项目。 它可能类似于: //declare an array, containing subproject names, which classes you want to collect def projectsToCollect = [':Base_Module',':A_Module'] //create a custom task, which assembles an jar-archive and ... -
我发现它,问题不在于Multi模块Graldle,Spring引导或Oauth2相关。 实际上,这是由于Gradle的src集合配置,其中Java应该位于Java src集文件夹中,而Kotlin位于Java src集文件夹中: sourceSets { main.java.srcDirs += 'src/main/java' main.kotlin.srcDirs += 'src/main/kotlin' } 正如Will Humphreys在他上面的评论中所说的那样,IntelliJ需 ...
-
如何使用Gradle编译带有客户端模块的Kotlin域模块?(How to compile Kotlin domain module with client module with Gradle?)[2022-03-12]
我为我的应用程序开发了以下架构:我有client , server和model模块,但我有一个单独的源目录,其中DTO称为dto (不是模块btw)。 这是构建的依赖层次结构: client依赖于dto server取决于model model取决于dto 使用这种层次结构模型仍然可以使用stdlib功能, server将与client模块共享所有DTO。 同时dto模块将使用stdlib如果它被编译为module依赖项)和stdlib-js如果它被编译为client依赖项),因此记住您可以在那里使用哪些类 ... -
Spring引导oauth2令牌(Spring boot oauth2 token)[2024-01-02]
@ComponentScan("the_actual_package")丢失了 @ComponentScan("the_actual_package") was missing -
是的,有一个EE回购需要一个由Mulesoft提供的用户名/密码组合。 如果您是客户,可以通过支持门户与他们联系。
mulesoft-ee-release Mulesoft EE https://repository.mulesoft.org/nexus-ee/content/repositories/releases-ee/ ... -
Sonar Intellij集成在一个多模块Gradle项目上(Sonar Intellij integration on a multi-module Gradle project)[2023-04-16]
我直接联系了Intellj,他们对我的回应是使用社区开发的插件(上面的尝试#2)。 鉴于答案和此处缺乏额外的反馈,答案似乎是声纳与Intellij 13的集成,目前可用的插件不支持多模块gradle java项目。 I contacted Intellj directly and their response to me was to use the community developed plugin (Attempt #2 above). Given that answer and the lack o ... -
使用Kotlin和Gradle(using Kotlin with Gradle)[2022-04-16]
这些类是Kotlin编译器的直接输出,之后应由Gradle打包到JAR中。 要构建JAR,您可以像在Java项目中一样运行jar任务: gradle jar 由于任务依赖性,此任务通常gradle build期间运行。 这将把Kotlin类打包成一个JAR存档(与其他JVM类一起,如果你有一个多语言项目),通常位于build/libs/ yourProjectName .jar 。 关于运行JAR,请参阅此问答以获取详细说明:( 链接) Thanks for @hotkey answer, it help ... -
构建脚本中似乎有一个拼写错误:工件的正确名称是kotlin-gradle-plugin (没有s )。 检查build.gradle的依赖项声明: classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:..." 它在这里的文档中描述: 使用Gradle There seems to be a typo in the build script: the correct name of the artifact is kotlin-gradle-plugin ...
-
你需要: apply plugin: 'spring-boot' 以及:) 导入依赖项是不够的。 You need to: apply plugin: 'spring-boot' as well :) Importing the dependency is not enough.
-
在build.gradle ,将ext.kotlin_version更改为: ext.kotlin_version = '1.1-M02' 这是一个小错误,IDE插件将自己的版本放入构建脚本,而不是Kotlin版本。 并且还将1.1 EAP存储库添加到buildscript和根范围中的repositories : repositories { // ... maven { url "http://dl.bintray.com/kotlin/kotlin-eap-1.1" } } 与EA ...